Does anybody know what is the limit for the number of values one can have in a list of expressions (to test for a match) for the IN clause?
You cannot have more than 1000 literals in an IN clause. You can, however, have SELECT statements in your IN clause which can return an unlimited number of elements i.e. You might try using 'between' clause replacing 'in'... check documentation for correct syntax on using between.
In Oracle we can't include more than 1000 values in the “IN” clause.
In Oracle we can only put up to 1000 values into an IN clause.
The SQL Server IN condition will return the records where expression is value1, value2..., or value_n. The SQL Server IN condition is also called the SQL Server IN operator.
Yes, there is a limit, but MSDN only specifies that it lies "in the thousands":
Including an extremely large number of values (many thousands) in an IN clause can consume resources and return errors 8623 or 8632. To work around this problem, store the items in the IN list in a table.
Looking at those errors in details, we see that this limit is not specific to IN
but applies to query complexity in general:
Error 8623:
The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.
Error 8632:
Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.
It is not specific but is related to the query plan generator exceeding memory limits. I can confirm that with several thousand it often errors but can be resolved by inserting the values into a table first and rephrase the query as
select * from b where z in (select z from c)
where the values you want in the in clause are in table c. We used this successfully with an in clause of 1-million values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With