单行字段拆分为多行
with t1 as
(
select '张三' c1,'胸外科,皮肤科' c2,date'2000-11-19' c3 from dual
union all
select '李四','胸外科',date'2001-01-04' from dual
union all
select '王五','妇产科,骨科',date'2001-01-08' from d……
[/Quote]
看不懂。。。能不能说简单点。。。
单行字段拆分为多行
with t1 as
(
select '张三' c1,'胸外科,皮肤科' c2,date'2000-11-19' c3 from dual
union all
select '李四','胸外科',date'2001-01-04' from dual
union all
select '王五','妇产科,骨科',date'2001-01-08' from dual
)
select c1,
substr(','||c2||',',instr(','||c2,',',1,b.rn)+1,
instr(c2||',',',',1,b.rn)-instr(','||c2,',',1,b.rn)) c2,c3
from t1,
(select rownum rn from t1
connect by rownum<10
--connect by rownum < nvl(length(regexp_replace(c2,'[^,]')),0)
) b
where length(c2)-length(replace(c2,','))+1>=b.rn
order by c1,b.rn
--10这个常量也可以改为读取字段中信息:nvl(length(regexp_replace(c2,'[^,]')),0)