Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a workaround for ORA-01795: maximum number of expressions in a list is 1000 error?

Tags:

sql

toad

Is there a workaround for

'ORA-01795: maximum number of expressions in a list is 1000 error'

I have a query and it is selecting fields based on the value of one field. I am using the in clause and there are 10000+ values

example:

select field1, field2, field3  from table1  where name in  ( 'value1', 'value2', ... 'value10000+' ); 

Every time I execute the query I get the ORA-01795: maximum number of expressions in a list is 1000 error. I am trying to execute the query in TOAD, no difference, the same error. How would I modify the query to get it to work?

Thanks in advance

like image 985
valmont74 Avatar asked Jul 24 '13 18:07

valmont74


People also ask

How do you handle ORA 01795 maximum number of expressions in a list is 1000?

This ORA-01795 errors are related with More than 254 columns or expressions were specified in a list. You should remove some of the expressions from the list. To solve this error, Use the “UNION” clause to join together two separate queries and make it appear like a single result table.

How do I fetch more than 1000 records in SQL?

To query more than 1000 rows, there are two ways to go about this. Use the '$offset=' parameter by setting it to 1000 increments which will allow you to page through the entire dataset 1000 rows at a time. Another way is to use the '$limit=' parameter which will set a limit on how much you query from a dataset.


1 Answers

Just use multiple in-clauses to get around this:

select field1, field2, field3 from table1  where  name in ('value1', 'value2', ..., 'value999')      or name in ('value1000', ..., 'value1999')      or ...; 
like image 191
Fabian Barney Avatar answered Sep 21 '22 06:09

Fabian Barney