首页 技术 正文
技术 2022年11月15日
0 收藏 521 点赞 5,103 浏览 1550 个字

在操作SQL中存在In的数量如果超过1000条会提示   ORA-01795: 列表中的最大表达式数为 1000

归纳有几种方式出现的:

第一种是:我在上一个 [jdbc 同时执行 查询和删除操]作中提到 在一个事务中在了in操作超出了 1000条,修改代码如下:

Connection conn = null;
        try {
            // 创建连接实例
            conn = JdbcUtility.GetFactory().CreateConn();
            conn.setAutoCommit(false);
            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

StringBuilder _strbd = new StringBuilder();
            _strbd.append(” delete from  table1  where id in ( “);
            _strbd.append(” select sp_1.table1 from  table2 “);
            _strbd.append(”  sp_1,sp_tcontentinfo sp_2  “);
            _strbd.append(” where sp_1.id=sp_2.id”);
            _strbd.append(”  ) “);
            Statement stmt = conn.createStatement();
           
            // 执行语句
            int r = stmt.executeUpdate(_strbd.toString());
            conn.commit();
            stmt.close();
            log.info(“清理数据成功!”);
        } catch (Exception ex) {
            if (null != conn) {
                try {
                    conn.rollback();
                } catch (SQLException se) {
                    log.error(“清理数据回滚失败!”);
                }
            }
            log.error(“清理数据失败,错误信息为:”+ex.getMessage());
        } finally {
            if (null != conn) {
                try {
                    conn.close();
                } catch (SQLException se) {
                    log.error(“清理数据,关闭数据库失败!”);
                }
            }
        }

第二种: 在单独的查询中

SQL里面的IN中的数据量不能超过1000条
解决办法:

例如

Select * from table_name where col in (‘col1’,’col2’ ……..)

如果in 后面的Item过多的话,超过1000就会出现这种错误。

解决方法是:

Select * from tablename where col in (‘col1’,’col2’ …….., ‘col1000’) or col in (‘col1001’, …………)

在构建SQL语句时稍微注意一下就好了。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,994
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,350
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845