我有一个表,其中的列数据采用以下格式(行号仅表示行号)。
Row#1 :test.doc#delimiter#1234,test1.doc#delimiter#1235,test2.doc#delimiter#1236<br> Row#2 :fil1.txt#delimiter#1456,fil1.txt#delimiter#1457
我想使用逗号(,)作为分隔符来分割字符串,将所有内容都列在单个列中,然后插入到新表中。
输出应该是这样的(行号只是表示行号):
Row#1:test.doc#delimiter#1234<br> Row#2:test1.doc#delimiter#1235<br> Row#3:test2.doc#delimiter#1236<br> Row#4: fil1.txt#delimiter#1456
谁能帮我做到这一点?
WITH data AS ( SELECT 'test.doc#delimiter#1234,test1.doc#delimiter#1235,test2.doc#delimiter#1236' AS "value" FROM DUAL UNION ALL SELECT 'fil1.txt#delimiter#1456,fil1.txt#delimiter#1457' AS "value" FROM DUAL ) SELECT REGEXP_SUBSTR( data."value", '[^,]+', 1, levels.COLUMN_VALUE ) FROM data, TABLE( CAST( MULTISET( SELECT LEVEL FROM DUAL CONNECT BY LEVEL <= LENGTH( regexp_replace( "value", '[^,]+')) + 1 ) AS sys.OdciNumberList ) ) levels;