日期:2014-05-17 浏览次数:20994 次
create table t_source_bj (库存编号 varchar2(10),名称 varchar2(20),零件备注码1 varchar2(20),零件备注码2 varchar2(20),零件备注码3 varchar2(20),零件备注码4 varchar2(20),合并项 varchar2(120)); insert into t_source_bj values('0704008','产品1','a','b','b','c','abbc'); insert into t_source_bj values('07043255','产品2','a','b','b','c','abbc'); insert into t_source_bj values('0702348','产品22','a','f','b','c','afbc'); insert into t_source_bj values('07432408','产品3','a','b','d','c','abdc'); insert into t_source_bj values('0723438','产品0','a','c','b','c','acbc');
update t_source_bj A set 合并项 =( select 合并项 from ( select 库存编号,replace(wm_concat(c),',','') 合并项 from ( select distinct 库存编号,c from ( select 库存编号,substr(合并项,rn,1) as c from t_source_bj a ,(select level rn from dual connect by 1=1 and level <=4)b where length(a.合并项)>=b.rn ) ) group by c ) B where A.库存编号 = B.库存编号 )
------解决方案--------------------
--表的别名有重复,不好意思,修改一下 update t_source_bj T_A set 合并项 =( select 合并项 from ( select 库存编号,replace(wm_concat(c),',','') 合并项 from ( select distinct 库存编号,c from ( select 库存编号,substr(合并项,rn,1) as c from t_source_bj a ,(select level rn from dual connect by 1=1 and level <=4)b where length(a.合并项)>=b.rn ) ) group by c ) T_B where T_A.库存编号 = T_B.库存编号