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

来源:互联网 发布:设计模式 知乎 编辑:程序博客网 时间:2024/06/03 12:48

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

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

select *  from table where id in (select 1 from dualunion allselect 2 from dual ……)

第二种,通过Wher 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 + " ))";                }



阅读全文
0 0
原创粉丝点击