Wednesday, 4 May 2022

REGEXP_SUBSTR use cases

Split the string
 
SELECT  
REGEXP_SUBSTR(' 123, 234, 345,','[0-9]+',1,level) "REGEXPR_SUBSTR2"  FROM DUAL
connect by REGEXP_SUBSTR(' 123, 234, 345,','[0-9]+',1,level) is not null


 SELECT  
REGEXP_SUBSTR(' 123, abc, 345,','[0-9]+|[a-z]+',1,level) "REGEXPR_SUBSTR2"  FROM DUAL
connect by REGEXP_SUBSTR(' 123, abc, 345,','[0-9]+|[a-z]+',1,level) is not null


Pull 4th word

SELECT
  regexp_substr( 'This is a regexp123_substr demo', '[[:alpha:]]+', 1, 4
  ) the_4th_word
FROM
  dual
 
  

Pull 4th alphanumeric word
  
  SELECT
  regexp_substr( 'This is a regexp123_substr demo', '[[:alnum:]]+', 1, 4
  ) the_4th_word
FROM
  dual

No comments:

Post a Comment