3,499
社区成员
发帖
与我相关
我的任务
分享
SQL> with A as ( select '(1,2,3,4,5)' a from dual),
2 B as ( select '1' no, '张三' name from dual
3 union all select '2' no, '李四' name from dual
4 union all select '3' no, '王五' name from dual
5 union all select '4' no, '李伟' name from dual
6 union all select '5' no, '小明' name from dual
7 union all select '6' no, '姗姗' name from dual
8 union all select '7' no, '丽丽' name from dual
9 union all select '8' no, '佳佳' name from dual
10 ),
11 C as ( select
12 instr( ','|| substr(A.a,2,length(A.a)-2) || ',' , ','|| B.no || ',') ind,
13 B.name
14 from A, B
15 where instr( ','|| substr(A.a,2,length(A.a)-2) || ',' , ','|| B.no || ',') > 0
16 )
17 select '('|| listagg(C.name,',') within group (order by C.ind) || ')' from C ;
'('||LISTAGG(C.NAME,',')WITHIN
--------------------------------------------------------------------------------
(张三,李四,王五,李伟,小明)
SQL>
select B.*
from B
inner join A
on ',' || cast(A.序号 as varchar2(20)) ||',' like '%,' || A.a ||',%'