Tuesday, July 5, 2016

How to find the value before or after Comma "," in Oracle sql?

using REGEXP_SUBSTR we can find out values before or after comma.


Here I am extracting the value before comma based on occurrence. The below code searches for a comma, return one or more occurrences of non-comma characters


SELECT REGEXP_SUBSTR ( 'KUMAR,SHIVAM,MYTHASS' , '[^,]+' , 1, 1) FROM DUAL;

The above code will extract the first occurrence of non-comma character.

If you want to extract the second occurrence of non-comma character, you need to find the second appearance-

SELECT REGEXP_SUBSTR ( 'KUMAR,SHIVAM,MYTHASS' , '[^,]+' , 1, 2) FROM DUAL;

Same way you can find Nth appearance of non-comma character.




No comments:

Post a Comment