需求 :
表A的b_ids字段存入了三个id分别是 a,b,c 其中是用字符隔开的
此时,又有B表的B.id字段需要关联A中的b_ids字段
如果此时用select a.* from A a ,B b where b.id in (a.b_ids)
或者select b.* from B b where b.id in (select a.b_ids from A a)
查出来都为空
是因为
A表中的a.b_ids查出来,是‘a,b,c ’ 而不是 a,b,c 多了单引号,需要做以下处理
select m.* from A a , B b WHERE b.id IN ( SELECT regexp_substr(a.b_ids,'[^,]+', 1, level) FROM DUAL CONNECT BY REGEXP_SUBSTR(a.b_ids, '[^,]+', 1, LEVEL) IS NOT NULL );
结果 比较理想,oracle还是没有mysql好用