Ticker

6/recent/ticker-posts

Convert Comma Separated Values into Table

 

The query can come quite handy when you have comma separated data string that you need to convert into table so that you can use other SQL queries like IN or NOT IN. Here we are converting ‘AA,BB,CC,DD,EE,FF’ string to table containing AA, BB, CC etc. as each row. Once you have this table you can join it with other table to quickly do some useful stuffs.

 

WITH csv

     AS (SELECT 'AA,BB,CC,DD,EE,FF'

                   AS csvdata

           FROM DUAL)

    SELECT REGEXP_SUBSTR (csv.csvdata, '[^,]+', 1, LEVEL) pivot_char

      FROM DUAL, csv

CONNECT BY REGEXP_SUBSTR (csv.csvdata,'[^,]+', 1, LEVEL) IS NOT NULL;




Post a Comment

0 Comments