Friday, September 27, 2013

Oracle Convert CSV to ROW

Allow Only Numeric values in the CSV : 
WITH parameter_csv AS (select :1 as val from dual)
SELECT  REGEXP_REPLACE(REGEXP_SUBSTR( val, '[^,]+', 1, LEVEL ),'[^0-9]','')  AS id
           FROM    parameter_csv
           CONNECT BY LEVEL <=
                LENGTH( REGEXP_REPLACE(val, '[^,]+', '' ) ) + 1


If you can afford it not to be parametrized (no ? marks in SQL) Needs Oracle 11g:
select * from xmltable('"this","is","my","csv"');
or 
select * from xmltable('1,2,3,4');

No comments:

Post a Comment