RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
将带分隔符的一行分为多行
今天遇到一个没做过的需求,要把带分隔符的一行多列数据按分隔符分为多行多列插入另个表,同时别的列保持不变,想了一会感觉变化后的数据比较难和变化前的关联起来,网上看了下几个案例,感觉:https://blog.csdn.net/mchdba/article/details/51946573 的方法比较不错,
例如源数据是这样
 将带分隔符的一行分为多行
目标数据是这样
将带分隔符的一行分为多行            

insert语句为:
insert into temp_0428_test2(pro_key,nip)
with temp0 as
 (select LEVEL lv from dual CONNECT BY LEVEL <= 100)
select pro_key, substr(t.vals, instr(t.vals, ',', 1, tv.lv) + 1, instr(t.vals, ',', 1, tv.lv + 1) - (instr(t.vals, ',', 1, tv.lv) + 1)) AS name
  from (select pro_key,
               ',' || nip || ',' AS vals,
               length(nip || ',') - nvl(length(REPLACE(nip, ',')), 0) AS cnt
          from temp_0428_test1) t
  join temp0 tv
    on tv.lv <= t.cnt
 order by 1;


这个方法不用和rownum做关联,避免了rownum增长后不能重置为1导致数据有缺失的问题                                                                                                                                  
网页标题:将带分隔符的一行分为多行
本文URL:http://sczitong.cn/article/jehdjh.html