Saturday, April 3, 2010

Split the single comma sperated row in multiple row

SELECT *
FROM (SELECT TRIM (SUBSTR (txt,
INSTR (txt, ';', 1, LEVEL) + 1,
INSTR (txt, ';', 1, LEVEL + 1) -
INSTR (txt, ';', 1, LEVEL) -
1
)) AS token
FROM (SELECT ';' || 'a;b;c;d;e;f;g;h' || ';' AS txt
FROM dual)
CONNECT BY LEVEL <= LENGTH (txt) - LENGTH (REPLACE (txt, ';', '')) - 1);


INPUT
-------
'a;b;c;d;e;f;g;h'

OUTPUT
-------
a
b
c
d
e
f
g
h

No comments:

Post a Comment