Sunday, August 10, 2014

Oracle Splitting String into multiple rows


I used below query to split a comma separated string to rows in oracle

select regexp_substr(a.col1,'[^,]+', 1, level) RT_PARAM_NAME from

        (select 'a,b,c,d' col1 from dual) a

        connect by regexp_substr(a.col1,'[^,]+', 1, level) is not null  



Note the regular expression '[^,]+' which basically tells the query to use , as a delimeter , and note the use of level and connect by.

No comments:

Post a Comment