Monday, March 21, 2011

SQL Query to split values seperated by comma

SELECT TRIM( SUBSTR ( txt , INSTR (txt, ',', 1, level ) + 1,
INSTR (txt, ',', 1, level+1) - INSTR (txt, ',', 1, level) -1) )         AS token  
FROM ( SELECT ','||:in_string||',' AS txt  FROM dual )
CONNECT BY level <= LENGTH(txt)-LENGTH(REPLACE(txt,',',''))-1


--Example
-------
--If value of in_string is entered as 1234,2,3,45,6,7,7,88,9,346

No comments:

Post a Comment