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

前端 未结 11 892
忘掉有多难
忘掉有多难 2020-11-27 16:14

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

11条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 16:45

    Some workaround solutions are:

    1. Split up IN clause

    Split IN clause to multiple IN clauses where literals are less than 1000 and combine them using OR clauses:

    Split the original "WHERE" clause from one "IN" condition to several "IN" condition:

    Select id from x where id in (1, 2, ..., 1000,…,1500);
    

    To:

    Select id from x where id in (1, 2, ..., 999) OR id in (1000,...,1500);
    

    2. Use tuples

    The limit of 1000 applies to sets of single items: (x) IN ((1), (2), (3), ...). There is no limit if the sets contain two or more items: (x, 0) IN ((1,0), (2,0), (3,0), ...):

    Select id from x where (x.id, 0) IN ((1, 0), (2, 0), (3, 0),.....(n, 0));
    

    3. Use temporary table

    Select id from x where id in (select id from );
    

提交回复
热议问题