限制 WHERE col IN (...) 条件 [英] Limit on the WHERE col IN (...) condition
本文介绍了限制 WHERE col IN (...) 条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码:
SELECT * FROM table
WHERE Col IN (123,123,222,....)
但是,如果我在 IN
子句中放入超过 3000 个数字,SQL 会抛出错误.
However, if I put more than ~3000 numbers in the IN
clause, SQL throws an error.
有谁知道是否有尺寸限制或类似的东西?!!
Does anyone know if there's a size limit or anything similar?!!
推荐答案
根据您使用的数据库引擎,指令的长度可能会有限制.
Depending on the database engine you are using, there can be limits on the length of an instruction.
SQL Server 有一个非常大的限制:
SQL Server has a very large limit:
http://msdn.microsoft.com/en-us/library/ms143432.aspx
ORACLE 有一个很容易达到的限制.
ORACLE has a very easy to reach limit on the other side.
因此,对于较大的 IN 子句,最好创建一个临时表,插入值并执行 JOIN.它的运行速度也更快.
So, for large IN clauses, it's better to create a temp table, insert the values and do a JOIN. It works faster also.
这篇关于限制 WHERE col IN (...) 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文