如何查找字段中用逗号隔开的id的列表

无爱大叔 2015-12-15 03:30:34
a表基础数据表
b表业务表,b表里字段aid存放了a表的id,形如:1,2,3

如何查出b表里某条记录对应a表1,2,3这3条记录的列表;错误的sql如下:
select a.* from a where aid in (select b.aid from b where b.id='AC2015021')
...全文
175 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zbdzjx 2015-12-15
  • 打赏
  • 举报
回复
with table1 as
(
select '1' id, 'a' col1 from dual union all
select '2' id, 'b' col1 from dual union all
select '3' id, 'c' col1 from dual union all
select '4' id, 'd' col1 from dual union all
select '5' id, 'e' col1 from dual
)
, table2 as
(
select '1,2,3' id_all from dual
)
select a.* from table1 a, table2 b where ',' || b.id_all || ',' like '%,' || a.id || ',%'

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧