Problem: I would like to show comma separated values as rows. How can I do it?
For example, I have following comma separated string and I want to show it as rows in tables.
String value: 'ABC,DEF,HIJ'
Expected output:

Solution:
Oracle -
SELECT EXTRACT (VALUE (d), '//row/text()').getstringval () AS MyColumn
FROM (SELECT XMLTYPE ( '<rows><row>'
|| REPLACE ('ABC,DEF,HIJ', ',', '</row><row>')
|| '</row></rows>'
) AS xmlval
FROM DUAL) x,
TABLE (XMLSEQUENCE (EXTRACT (x.xmlval, '/rows/row'))) d;
For example, I have following comma separated string and I want to show it as rows in tables.
String value: 'ABC,DEF,HIJ'
Expected output:
Solution:
Oracle -
SELECT EXTRACT (VALUE (d), '//row/text()').getstringval () AS MyColumn
FROM (SELECT XMLTYPE ( '<rows><row>'
|| REPLACE ('ABC,DEF,HIJ', ',', '</row><row>')
|| '</row></rows>'
) AS xmlval
FROM DUAL) x,
TABLE (XMLSEQUENCE (EXTRACT (x.xmlval, '/rows/row'))) d;
No comments:
Post a Comment