现有由多个诊断组成的字段,诊断个数不定,由英文逗号拼接。
现需要将字段分解,每条诊断列为一行。
转化前字段如下图:
转化后字段如下图:
SQL实现方法如下:
select a.id,
substr(编码,instr(编码,',',1,levels.lvl)+1,instr(编码,',',1,levels.lvl+1)-(instr(编码,',',1,levels.lvl)+1)) as 诊断编码
from (select id,','||t.amb_diagnosis||',' 编码,length(t.amb_diagnosis)-nvl(length(replace(t.amb_diagnosis,',')),0)+1 cnt
from CLINIC_AMB_ORDER_LIST t) a,
(select rownum as lvl
from (select max(length(t.amb_diagnosis||',')-nvl(length(replace(t.amb_diagnosis,',')),0)) max_len
from CLINIC_AMB_ORDER_LIST t)
connect by level<=max_len
) levels
where levels.lvl<=a.cnt
and a.id=5393232
order by a.id
CSDN链接:https://blog.csdn.net/m0_47101212/article/details/126623186
标签:编码,amb,转列,levels,diagnosis,oracle,lvl,id From: https://www.cnblogs.com/long-long-ago/p/17648591.html