Regular Expressions in Oracle

Asked

Viewed 282 times

1

'Select from CITIES tables only records with composite names separated by a single space'

TABLE CIDADES

ID  CIDADE
01  SAO PAULO
02  RIO DE JANEIRO
03  SAO CARLOS
04  TAUBATÉ
05  SÃO JOSÉ DO RIO PRETO

The Query can return only

TABLE CIDADES

ID  CIDADE
01  SAO PAULO
03  SAO CARLOS

HOW TO WRITE A REGULAR EXPRESSION THAT RETURNS TO ME CITIES COMPOSED OF ONLY 2 NAMES?

2 answers

2


I’m going to assume we do this check for the number of spaces...

 select * from cidades 
 where regexp_count(cidade,' ')=1
  • Thank you very much, you helped me a lot.

1

For cases where there is more than one space, one option is this:

SELECT * FROM CIDADES 
WHERE REGEXP_COUNT(CIDADE, '[[:alpha:]]\s{1,}[[:alpha:]]') =  1;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.