oracle in 超过1000解决方案

4 篇文章 0 订阅

oracle in 超过1000解决方案

1.with as table建立临时表子查询
with t as (
    select '1' as id from dual
    union all
    select '2' as id from dual
    ·····
)
select i.*
from table1 i
where i.id in (
    select t.id from t
)
2.使用or

方式1:

select * from table where id in (1, 2, ..., 1000) or id in(1001, ....., 1999)

后台使用

    public String createSql(String col ,List<Integer> umIds) {
        StringBuffer sb = new StringBuffer();
        sb.append(col + " in(");
        int size = umIds.size();
        int index = 0;
        for (int i = 0; i < size; i++) {
            index++;
            if (index == 999) {
                index = 0;
                sb.append(")");
                sb.append("  or " + col + " in ( ");
            }
            if (index + 1 == 999 || size - 1 == i) {
                sb.append("" + umIds.get(i) + "");
            } else {
                sb.append("" + umIds.get(i) + ",");
            }
        }
        sb.append(")");
        return sb.toString();
    }

方式2:

select * from table where id =1 or id =2 or·····

超过1000报错:

<isNotEmpty property="ids" prepend="and">
    t.id in
    <iterate open="(" close=")" conjunction="," property="ids">
        #ids[]#
    </iterate>
</isNotEmpty>

更正:

<isNotEmpty property="ids" prepend="and">
    <iterate open="(" close=")" conjunction=" or " property="ids">
        t.cltno = #ids[]#
    </iterate>
</isNotEmpty>

前面是比较老的ibatis写法,在mybatis3里面你可以这样做

 <if test="scope.ids!= null and scope.ids.size() > 0">
                and (D.PAY_CLT_NO in
                <foreach collection="scope.ids" open="(" close=")" separator="," item="id" index="idx">
                    <if test="idx != 0 and idx % 999 == 0 and idx != scope.ids.size() - 1">
                        #{id}) or D.PAY_CLT_NO in (#{id}
                    </if>
                    <if test="idx == 0 or (idx % 999 != 0 or idx == scope.ids.size() - 1)">
                        #{id}
                    </if>
                </foreach>
                )
            </if>
3.后台拼接查询,返回后重组list

传给后台参数LIST数组大小超过1000,截取查询两次,最后addAll();

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值