有两个表的关系是这样的。
table1:
id iid
1 A,B
2 B,C,D
3 A,D
TABLE2:
ID MC
A this is a
B this is B
C this is B
我想通过tbale1的ID做为参数传值,查询TABLE2包含在TBALE1.iid中的所有记录。
现在我已有split函数来拆分IID,请问要实现我上述的需求要怎么写呢?
------解决方案--------------------
- SQL code
with table1(id,iid) as(select 1,'A,B' from dualunion all select 2,'B,C,D' from dualunion all select 3,'A,D' from dual),table2(id,mc) as(select 'A','this is a' from dualunion all select 'B','this is b' from dualunion all select 'C','this is c' from dual)select * from table2where exists(select 1 from table1 where table1.id=1--此处传你的id and instr('%,'||iid||',%',','||table2.id||',')>0);/*I MC - --------- A this is a B this is b */