I have a data in CSV format (comma separated values) like follows:
first,second,third,fourth,fifth
I want the output as follows:
column_value
first
second
third
fourth
fifth
The easiest way to achieve is to use a CONNECT BY clause in DUAL table and to populate the results. Here is the query:
SELECT substr(str, instr(str, ',', 1, LEVEL) + 1, instr(str, ',', 1, LEVEL + 1) - instr(str, ',', 1, LEVEL) - 1) column_value
FROM (SELECT ',' || '&mystring' || ',' str FROM dual)
CONNECT BY LEVEL <= length(str) - length(REPLACE(str, ',')) - 1;
Pass value first,second,third,fourth,fifth to mystring.
first,second,third,fourth,fifth
I want the output as follows:
column_value
first
second
third
fourth
fifth
The easiest way to achieve is to use a CONNECT BY clause in DUAL table and to populate the results. Here is the query:
SELECT substr(str, instr(str, ',', 1, LEVEL) + 1, instr(str, ',', 1, LEVEL + 1) - instr(str, ',', 1, LEVEL) - 1) column_value
FROM (SELECT ',' || '&mystring' || ',' str FROM dual)
CONNECT BY LEVEL <= length(str) - length(REPLACE(str, ',')) - 1;
Pass value first,second,third,fourth,fifth to mystring.
No comments :
Post a Comment