关于where in(字符串) (oracle )

如是我闻2012 2018-01-02 01:34:39
比如:b表ids字段数据

id ids
---------------------------
1 321,322,323,404,405
2 112,113,114,115,116,117

用拼接多行
select wm_concat(ids) as ids from b


a表id=b表ids值

id name
------------------------
321 xxx
322 ccc
114 bbb

用 select * from a where id in(select wm_concat(ids) as ids from b)
是不可行的,提示
ORA-01722: 无效数字
01722. 00000 - "invalid number"


oracel不是很精通,请问大师们怎样实现查询结果?
...全文
755 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
自由自在_Yu 2018-01-04
  • 打赏
  • 举报
回复
select * from a,b where instr(b.ids,a.id) <> 0
查询结果: 321 xxx 1 321,322,323,404,405 322 ccc 1 321,322,323,404,405 114 bbb 2 112,113,114,115,116,117
bossft_long 2018-01-03
  • 打赏
  • 举报
回复
不要wm_concat,用like查
kk_lucky 2018-01-02
  • 打赏
  • 举报
回复
引用 2 楼 lishunwen0825 的回复:
[quote=引用 1 楼 mnvad 的回复:] 为什么一定要用拼接呢 select * from a where id in(select ids from b) 这样的功能是一样的 啊
引用 1 楼 mnvad 的回复:
为什么一定要用拼接呢 select * from a where id in(select ids from b) 这样的功能是一样的 啊
是的不拼接也可以,但是ids是字符串,无法执行 [/quote]用to_number()转换一下
如是我闻2012 2018-01-02
  • 打赏
  • 举报
回复
引用 1 楼 mnvad 的回复:
为什么一定要用拼接呢 select * from a where id in(select ids from b) 这样的功能是一样的 啊
引用 1 楼 mnvad 的回复:
为什么一定要用拼接呢 select * from a where id in(select ids from b) 这样的功能是一样的 啊
是的不拼接也可以,但是ids是字符串,无法执行
kk_lucky 2018-01-02
  • 打赏
  • 举报
回复
为什么一定要用拼接呢 select * from a where id in(select ids from b) 这样的功能是一样的 啊

81,091

社区成员

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

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