oracle in 超过1000
拼接效果为 where ( id in ([0-999]) or id in ([1000-1999]) )
亲测好用
<where>
<if test="list != null and list.size > 0">
(id IN
<!-- 处理in的集合超过1000条时Oracle不支持的情况 -->
<trim suffixOverrides=" OR id IN()">
<foreach collection="list " item="Id" index="index" open="(" close=")">
<if test="index != 0">
<choose>
<when test="index % 1000 == 999">) OR id IN (</when>
<otherwise>,</otherwise>
</choose>
</if>
#{Id}
</foreach>
</trim>
)
</if>
)
文章介绍了当Oracle查询中IN子句的元素超过1000个时,如何通过SQL拼接技巧,将大集合分割成多个小于1000的子集,以避免Oracle的限制。使用了IF和FOREACH循环以及TRIM函数来动态生成OR条件,确保查询的正常执行。
1768

被折叠的 条评论
为什么被折叠?



