第1个回答 2013-03-22
有两个思路供参考:
1. 使用字符串比较的方法
select *
from 表A a, 表B b
where instr(a.id, ','||b.id||',') <> 0
之所以使用 ','||b.id||',' 是因为如果表A中的ID为:123,456,789 那么B表中的ID为4也只可以查出来,但两边加了逗号以后就不会查出来了
2. 使用分隔字符串的方式,有些烦琐
select *
from 表B t,
(select trim(regexp_substr(id, '[^,]+', 1, IDX)) fid
from 表A a,
(select level IDX
from dual
connect by level <=
(length(id) - length(replace(id, ',', '')) + 1)) b
) s
where t.id = b.fid
这里面用到了 regexp_substr 字符串分隔的方法,你可以看一下
第4个回答 2013-03-22
select * from b where id in(
select replace(regexp_substr(names,'[^,]+',1,level),',',' ') from a
--加上 a 表的筛选条件
connect by level<=length(names)-length(replace(names,'<,>',''))+1 )本回答被网友采纳