请问如何根据字段值中的逗号来拆分,并把拆分的数据保存到新表中?
旧表tbl1
IDYUANGONG
106057863,6081791,6102168
116045986,6102305,6086817
126052191,6041969
136072396,6077206,6051936,6091173
如何根据YUANGONG字段中的“,”来拆分保存到新表tbl2中去?
新表tbl2
IDYUANGONG
106057863
106081791
106102168
116045986
116102305
116086817
.......
136091173
请大家帮忙看下
[解决办法]
connect by
start with
递归调用。
[解决办法]
insert into tb2(ID YUANGONG) select id,regexp_substr(YUANGONG,'[^,]+',1,n) from tb1 left join (select level from dual connect by level < 10/*这里自己调整一下,用SQL也能做到,但是没有太大意义*/)nn on 1=1 where regexp_substr(YUANGONG,'[^,]+',1,n) is not null