【mybatis标签改造】java.sql.SQLException: ORA-01795: 列表中的最大表达式数为 1000

改造前

...
cc.credit_id IN
<foreach collection="queryParam.creditIds" open="(" close=")" item="items" separator="," >
    #{items}
</foreach>

问题: 单次in最多支持1000个

方案:最小改动方案,用or拼接多个in,效果 - - in() or in() or in()

改造后

...
(cc.credit_id IN
<foreach collection="queryParam.creditIds" open="(" close=")" item="items" index="index">
    <if test="index != 0">
        <choose>
            <when test="index % 1000 == 999">) OR cc.credit_id IN (</when>
            <otherwise>,</otherwise>
        </choose>
    </if>
    #{items}
</foreach>
)
  1. index != 0 [ 避免 in 中开头为 , ]
  2. 每逢999 则拼接到新的in中

猜你喜欢

转载自blog.csdn.net/ZHAI_KE/article/details/127862166
今日推荐