oracle数据库一个表字段中存了id,并以逗号分隔,id对应的详细信息在另一个表中

0
现在有两个表,表a中

aid       主管领导
1            1,2,3
2             2,4

表b中

bid              姓名
1                李一
2                刘二
3                张三
4                李四
 
怎么联合查询出
 序号       主管领导            主管领导姓名
1            1,2,3               李一,刘二,张三
2             2,4                       刘二,李四

求救!!!!
已邀请:
1

老头子 - 专注是唯一的捷径 2015-11-06 回答

只能先拆开,再合并了
with laotouzi as (
select leader, regexp_substr(leader, '[^,]+', 1, level) value,aid
  from a
connect by leader = prior leader
       and instr(leader || ',', ',', 1, level) > 0
       and prior dbms_random.value is not null
)
select aid,wm_concat(name)
from laotouzi aa,b
where aa.value = b.bid
group by aid

要回复问题请先登录注册