Site icon IT Tutorial

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

I got ” ORA-01795: maximum number of expressions in a list is 1000 ” error in Oracle database.

 

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

 

Details of error are as follows.

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

Cause: More than 254 columns or expressions were specified in a list.

Action: Remove some of the expressions from the list.





 

 

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.

Here is a simple example that demonstrates how to use the UNION clause.


-- Create the table and insert values

drop table test1;
create table test1 ( STRU_ID varchar2(20), anything varchar2(10));
insert into test1 values ( 'AB-00030320', '1');
insert into test1 values ( 'AB-00021219', '2');
insert into test1 values ( 'AB-00021220', '3');
insert into test1 values ( 'AB-00001218', '4');
insert into test1 values ( 'AB-00013926', '5');
insert into test1 values ( 'AB-00023207', '6');
insert into test1 values ( 'AB-00019535', '7');
insert into test1 values ( 'AB-00015056', '8');
insert into test1 values ( 'AB-00017218', '9');
insert into test1 values ( 'AB-10021219', '10');
insert into test1 values ( 'AB-1121219', '11');
insert into test1 values ( 'AB-12021219', '12');
insert into test1 values ( 'AB-13021219', '13');
insert into test1 values ( 'AB-14021219', '14');

-- The table has 8 rows

SQL> select distinct stru_id, anything
         from test1
         where stru_id in
        ('','AB-00030320','AB-00021219','AB-00021220','AB-00001218','AB-00013926','AB-00003207','AB-00019535','AB-00015056','AB-00017218');

STRU_ID ANYTHING
-------------------- ----------
AB-00001218 4
AB-00019535 7
AB-00021219 2
AB-00013926 5
AB-00030320 1
AB-00021220 3
AB-00015056 8
AB-00017218 9

8 rows selected.

-- First query returns 5 rows.

SQL> select distinct stru_id,anything
         from test1
        where stru_id in
         ('','AB-00030320','AB-00021219','AB-00021220','AB-00001218','AB-00013926');

STRU_ID ANYTHING
-------------------- ----------
AB-00001218 4
AB-00021219 2
AB-00013926 5
AB-00030320 1
AB-00021220 3

5 rows selected.

-- Second query returns 3 rows.

SQL> select distinct stru_id,anything
          from test1
          where stru_id in
          ('AB-00019535','AB-00015056','AB-00017218');

STRU_ID ANYTHING
-------------------- ----------
AB-00019535 7
AB-00015056 8
AB-00017218 9

3 rows selected.

-- By combining both queries with UNION clause, 8 rows are returned.

SQL> select distinct stru_id,anything
          from test1
          where stru_id in
         ('','AB-00030320','AB-00021219','AB-00021220','AB-00001218','AB-00013926') UNION select distinct stru_id,anything from test1 where stru_id in
        ('AB-00019535','AB-00015056','AB-00017218');

STRU_ID ANYTHING
-------------------- ----------
AB-00001218 4
AB-00013926 5
AB-00015056 8
AB-00017218 9
AB-00019535 7
AB-00021219 2
AB-00021220 3
AB-00030320 1

8 rows selected.



Another simple workaround is to create a table TMP_TRIPLET where you would insert the data “more than 1000 value”:


SQL> select distinct stru_id,anything
from test1
where stru_id in
(select * from TMP_TRIPLET)

 

WARNING :  Please check the performance in test env if you are using it with large set of values. This may cause performance issue for the query because of the high number of bind variables being parsed.

It may also cause huge size problem for with the SQLBINDS area of the SYSAUX AWR component.

 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 

Exit mobile version