数据库:SqlServer 2008 R2
sqlserver异常:传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此RPC请求中提供了过多的参数。最多应为2100。
使用mybatis写的查询语句,用
select
, a.zdba_year, a.is_jlzd, a.zdba_yfxms, a.zdba_jftr, , , , , a.is_gxqqy,
from ZD_Zdba a
where in
<foreach item="id" index="index" collection="ids" open="(" separator="," close=")">
#{id}</foreach>将参数进行遍历,数据量为4000此时就会报错。
解决方法是替换in查询使用exists查询。但如何对sql进行改造呢?
select
, a.zdba_year, a.is_jlzd, a.zdba_yfxms, a.zdba_jftr, , , , , a.is_gxqqy,
from ZD_Zdba a
where 1=1 and
<foreach item="id" index="index" collection="ids" open="(" separator="or" close=")">
EXISTS (select 1 from ZD_Zdba b where = #{id} and =)
</foreach>
经测试发现该方法换汤不换药,还是无法解决参数过多的问题。
最终的解决办法是不使用