Páginas

segunda-feira, 3 de outubro de 2016

[Oracle] - Utilizando regex para consultas


Bom pessoal, essa postagem é para auxiliar na utilização de expressões regulares no Oracle, facilitando a codificação de procedimentos armazenados e funções:

-- SOMENTE DIGITOS
SELECT regexp_replace('João 23 Paulo 11 Pinheiro 78','[^\/[:digit:]]') AS NUMEROS FROM DUAL;


--ADICIONA ESPAÇO ONDE FALTA
WITH mydata(str) AS
(
   SELECT  ' a b c d  efg h'   FROM DUAL UNION ALL
   SELECT  ' a b c d e f g h ' FROM DUAL UNION ALL
   SELECT  'a b c d e f g h'   FROM DUAL UNION ALL
   SELECT  'abcdefgh'          FROM DUAL
)
SELECT CASE INSTR(TRIM(str),' ')
         WHEN 0 THEN
            str
         ELSE
            TRIM(REGEXP_REPLACE(str,'(\S)\s*','\1 '))
         END AS str
  FROM mydata;



--REMOVER ESPAÇOS DUPLOS
WITH NOME(STR) AS
(
     SELECT 'ana  clara de souza   prado' FROM DUAL UNION ALL
     SELECT 'PEDRO  LOPES   PINHEIRO' FROM DUAL UNION ALL
     SELECT 'mARIA DA gloria PINHEIRO' FROM DUAL
)
SELECT REGEXP_REPLACE(UPPER(TRIM(STR)),'( ){2,}', ' ') AS STR
FROM NOME;



--ALTERA STRING
SELECT REGEXP_REPLACE('I cannot see you.','\.',' in the dark.') 
REGEXT_SAMPLE
FROM dual;


Espero que estes exemplos ajudem. Graça e Paz sejam com todos.

Um comentário:

  1. When weighing up actual cash on line casino apps, you must to}, to begin with|to start with}, discover out whether there even is an app , and whether it’s appropriate with both Android and iOS units. You also needs to|must also} examine the person interface to 로스트아크 verify it looks and feels right on your gadget. With its number of 350+ video games, Wild Casino presents a comprehensive cellular on line casino experience. But it’s with a high-quality number of 11 blackjack video games the place we feel the site stands out, and the place it would attraction to players with an appetite for beating the dealer. It can also be|can be} essential to remember that that|do not neglect that} while gambling is rising rapidly plenty of} places, in others it is totally or partially prohibited. As properly as within the majority of the US, sports betting towards the law|is unlawful} in India, Pakistan, and China, three of the most important gambling markets on the earth.

    ResponderExcluir