您的位置:首页 > 数据库 > Oracle

Oracle查询中IN参数超过1000的解决方法

2017-06-29 17:41 671 查看
在查询一个in中超过1000个参数的时候报错了,查找了下,这边总结的解决方法有两种,一种是通过union all,一种是循环将参数写到in中再用or连接语句。方法还有几种但是暂未尝试,先不进行记录。开发中主要用了第二种方法。

第一种,写法上没有个数限制,不过还是需要建个临时表,语句如下:

select *
from table
where id in (
select 1 from dual
union all
select 2 from dual
……)


第二种,通过Where or,将in中的参数控制在1000之内

if (e.SelectKeyValues.Count > 0)
{
string whereKey = string.Empty;
for (int i = 0; i < e.SelectKeyValues.Count(); i++)
{
if (i == (e.SelectKeyValues.Count() - 1))
{
whereKey += "'" + e.SelectKeyValues[i] + "'";
}
else if ((i % 999) == 0 && i > 0)
{
whereKey += "'" + e.SelectKeyValues[i] + "') or 质量特性编码 in ( ";
}
else
{
whereKey += "'" + e.SelectKeyValues[i] + "',";
}
}
where += " and (质量特性编码 in ( " + whereKey + " ))";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: