17,382
社区成员




table1
id typeid1 typeid2 typeid3 typeid4
1 1 2 3 1,2,3
table2
id typename
1 项目1
2 项目2
3 项目3
结果:
id typeid1 typeid2 typeid3 typeid4
1 项目1 项目2 项目3 项目1,项目2,项目3
with a as
(
select 1 id, '1' typeid1, '2' typeid2, '3' typeid3, '1,2,3' typeid4 from dual
)
,
b as
(
select '1' id, '项目1' name from dual union
select '2' , '项目2' from dual union
select '3' , '项目3' from dual
)
select a.id, b1.name, b2.name, b3.name, b1.name||','||b2.name||','||b3.name from a,b b1,b b2,b b3 where a.typeid1 = b1.id and a.typeid2 = b2.id and a.typeid3 = b3.id;
with a as
(
select 1 id, '1' typeid1, '2' typeid2, '3' typeid3, '1,2,3' typeid4 from dual
)
,
b as
(
select '1' id, '项目1' name from dual union
select '2' , '项目2' from dual union
select '3' , '项目3' from dual
)
select t.id,b1.name,b2.name,b3.name,wm_concat(b4.name)
from
(select a.id,a.typeid1,a.typeid2,a.typeid3,regexp_substr(a.typeid4,'[^,]+', 1, tr.lv) typesubid,tr.lv from a,(select level lv from dual connect by level < 10) TR) T,
b b1,b b2,b b3,b b4
where typesubid is not null and
t.typeid1 = b1.id and
t.typeid2 = b2.id and
t.typeid3 = b3.id and
t.typesubid = b4.id
group by t.id,b1.name,b2.name,b3.name ;