Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Obter valor entre a 2ª e a 3ª vírgula

select 
  regexp_substr('2901 MAIN ST,CORNING,NY,14830', '(.*?,){2}(.*?),', 1, 1, '', 2) 
from dual

No geral,
n_th_component := 
  regexp_substr(string, '(.*?,){'||(n-1)||'}([^,]*)', 1, 1, '', 2);

Exemplo:
select 
  n,  
  regexp_substr('2901 MAIN ST,CORNING,NY,14830', 
                '(.*?,){'||(n-1)||'}([^,]*)', 1, 1, '', 2)
from (select level n from dual connect by level <= 4)