3,499
社区成员
发帖
与我相关
我的任务
分享
with tab as(
select 'test' name,'a,b,c,aa,d' id from dual
)
select name,regexp_substr(id,'[^,]+',1,level) as newid
from tab
connect by
level<=length(id)-length(replace(id,',',''))+1
NAME NEWID
------------
test a
test b
test c
test aa
test d
SQL> create table ta as
2 select 'a,b,c,aa,d' chr from dual
3 /
Table created
SQL> select * from ta;
CHR
----------
a,b,c,aa,d
SQL> create table tb as
2 select * from ta
3 where 1=0
4 /
Table created
SQL> select count(*) from tb;
COUNT(*)
----------
0
SQL> insert into tb
2 select regexp_substr(chr,'[^,]+',1,level) chr
3 from ta
4 connect by
5 level <= length(chr)-
6 length(replace(chr,',',''))+1
7 /
5 rows inserted
SQL> select * from tb;
CHR
----------
a
b
c
aa
d
SQL>