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

倖福魔咒の 提交于 2020-07-22 05:42:25

问题


I'm trying to run a query with NOT IN clause like:

SELECT * FROM table WHERE column NOT IN (?,?,...) (>1000 items) and I'm getting ORA-01795: maximum number of expressions in a list is 1000 error.

In my script I'm doing something like:

my $lparam = join ', ' => ('?') x @ids; 
$lquery = "SELECT * FROM table WHERE column NOT IN ($lparam)";

$lcsr = $zdb->prepare($lquery);
$lcsr->execute( @ids );

I want to split the NOT IN clause to something like where (A not in (a,b,c) AND A not in (d,e,f)) ... How can we achieve this?


回答1:


Here you go, adding triples and counting them.

my $count = 0;
$lquery = "SELECT * FROM table WHERE (A ";
while (@ids -$count > 3)  {
    $lquery .= "NOT in (?, ?, ?) AND A ";
    $count += 3;
}
my $lparam = join ', ' => ('?') x (@ids - $count); 

$lquery .= "NOT  IN ($lparam))";



回答2:


You can go with the IN list using a combination of the column as follows:

SELECT * FROM table WHERE (column,1) NOT IN ((?,1),(?,1),...) (>1000 items)

Here, 1 is used as the second column. And you can give more than 1000 values in the IN clause list. It is a workaround of skipping the limit.



来源:https://stackoverflow.com/questions/62507305/ora-01795-maximum-number-of-expressions-in-a-list-is-1000-error-in-perl-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!