how to add more than 1000 values with NOT IN clause(如何使用 NOT IN 子句添加超过 1000 个值)
问题描述
我想在 NOT IN 子句中使用逗号分隔的 ID.我正在使用 oracle 11g.
I have comma delimited id's that I want to use in NOT IN clause.. I'm using oracle 11g.
select * from table where ID NOT IN (1,2,3,4,...,1001,1002,...)
结果
ORA-01795: maximum number of expressions in a list is 1000
我不想使用临时表.正在考虑这样做
I don't want to use temp table. am trying considering doing this
select * from table1 where ID NOT IN (1,2,3,4,…,1000) AND
ID NOT IN (1001,1002,…,2000)
有没有其他更好的解决方法来解决这个问题?
Is there any other better workaround to this issue?
推荐答案
你说你不想,但是:使用临时表.这就是正确的解决方案.
You said you don't want to, but: use a temporary table. That's the correct solution here.
在 Oracle 中查询解析的开销很大,这就是将数千个标识符放入一个巨大的 SQL 块中时会得到的结果.此外,还有定义不明确的限制 关于您要命中的查询长度.另一方面,对表进行反联接... Oracle 擅长于此.将数据批量加载到表中,Oracle 也很擅长.使用临时表.
Query parsing is expensive in Oracle, and that's what you'll get when you put thousands of identifiers into a giant blob of SQL. Also, there are ill-defined limits on query length that you're going to hit. Doing an anti-JOIN against a table, on the other hand... Oracle is good at that. Bulk loading data into a table, Oracle is good at that too. Use a temp table.
将 IN
限制为一千个条目是一种完整性检查.你击中它的事实意味着你正在尝试做一些疯狂的事情.
Limiting IN
to a thousand entries is a sanity check. The fact that you're hitting it means you're trying to do something insane.
这篇关于如何使用 NOT IN 子句添加超过 1000 个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 NOT IN 子句添加超过 1000 个值


基础教程推荐
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01