zoukankan      html  css  js  c++  java
  • java.sql.SQLSyntaxErrorException: ORA-01795: 列表中的最大表达式数为 1000

    后台报了一些异常日志,查阅后发现在 oracle 数据库中使用 in 关键字条件不能超过 1000 个,当时写查询语句时没有关注这个问题

    总结一下解决方法

    1.分多次查询,对查询要求不高的话。把入参的集合按照每个最大1000个来处理,分几次查询,然后把结果进行汇总,这样就只用改动代码,不用改动SQL。

    2.把参数分开但还是一次查询,使用 or 连接

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

    3.在 in 后面接一个查询语句

    select * from A where id in (select id from B)

    4.与 3 类似,使用 with  as 语法,把条件封装成一个表

    with temp as (select * from A)
    select * from B where id in (select id from temp)
  • 相关阅读:
    groovy 执行shell
    expect 用法
    shebang解释
    docker 安装
    centos7 lvm添加硬盘后扩展磁盘空间
    scoped的原理和deep深度选择器的妙用
    swagger3
    帮评网
    反射工具
    网络只能传输二进制
  • 原文地址:https://www.cnblogs.com/jhxxb/p/10830547.html
Copyright © 2011-2022 走看看