Wednesday, 13 June 2012

Oracle getting nth string from comma separated string

For example getting 2nd string from 'CAT,DOG,MOUSE,RAT,BAT,CAR,DOOR,LOCK'  will be DOG

SELECT REGEXP_SUBSTR(MYCOL, '[^,]+', 1, 2) AS VAL
FROM
(
   SELECT 'CAT,DOG,MOUSE,RAT,BAT,CAR,DOOR,LOCK' AS MYCOL FROM DUAL
);

No comments:

Post a Comment