关于where in(字符串)

如是我闻2012 2018-01-02 01:39:25
比如: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不是很精通,请问大师们怎样实现查询结果,spring+mybaties
...全文
459 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
自由自在_Yu 2018-01-04
  • 打赏
  • 举报
回复
引用 5 楼 yuxiangaaaaa 的回复:
select * from a,b where instr(b.ids,a.id) <> 0
查询结果: a.id a.name b.id b.ids 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
用instr函数,在b.ids里面查找a.id出现的位置,找不到就返回值0
自由自在_Yu 2018-01-04
  • 打赏
  • 举报
回复
select * from a,b where instr(b.ids,a.id) <> 0
查询结果: a.id a.name b.id b.ids 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
如是我闻2012 2018-01-03
  • 打赏
  • 举报
回复

select * from a where id in(select ids from b);
结果如下:
ORA-01722: 无效数字
01722. 00000 -  "invalid number"
有说用to_number,但这个不知怎么用?
碧水幽幽泉 2018-01-02
  • 打赏
  • 举报
回复
SQL实现如下

 select * from a where id in(select ids from b);
卖水果的net 2018-01-02
  • 打赏
  • 举报
回复
-- 直接这样就可以了,不用拼接。  select * from a where id in(select ids from b)
  • 打赏
  • 举报
回复
你得拆开,才能用字段的方式 不然instr()>0的方式 考虑看看

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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