table 1 :
code wgz06
2 001,0002
3 001,0002,00003
table 2:
id name
001 数学
0002 体育
00003 美术
要求结果
code sql_name
1 数学
2 数学,体育
3 数学,体育,美术 收起
code wgz06
2 001,0002
3 001,0002,00003
table 2:
id name
001 数学
0002 体育
00003 美术
要求结果
code sql_name
1 数学
2 数学,体育
3 数学,体育,美术 收起
只需要查询出结果
with
temp1
as
(
select
a.*,length(wgz06)-length(
replace
(wgz06,
','
))+1 my_rn
from
table1 a
),temp2
as
(
select
rownum rn
from
dual
connect
by
rownum<=(
select
max
(my_rn)
from
temp1)
)
select
a.code,wm_concat(b.
name
) sql_name
from
(
select
a.code,regexp_substr(a.wgz06,
'[^,]+'
,1,b.rn) new_id
from
temp1 a
join
temp2 b
on
a.my_rn>=b.rn) a ,table2 b
where
a.new_id=b.id
group
by
a.code