How to enter binds for a multi-valued parameter in SQL Developer

回眸只為那壹抹淺笑 提交于 2019-12-01 21:27:17

This isn't a SQL Developer restriction, it's just how bind variables work. You're effectively doing:

select count(*) from foo 
where foo.id in ('1,2,3')

... which is really in (to_number('1,2,3')), hence the error. It'll work for a single value, give odd results for two values if your decimal separator is a comma, and fail for anything more.

You can't enter multiple values at a bind prompt, or supply multiple values to an in() with a single bind. You can cheat be a bit inventive though. The xmltable function will convert the comma-separated string into rows with one value in each:

var ids varchar2(50);
exec :ids := '1,2,3';
select * from xmltable(:ids);

COLUMN_VALUE
------------
1            
2            
3            

You can then use that as a look-up table:

select count(*)
from xmltable(:ids) x
join foo f on f.id = to_number(x.column_value);

  COUNT(*)
----------
         3 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!