I have a select statement which delivers the wrong number of rows.
I can reproduce the problem on Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
and on Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
I can not reproduce it on Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
Testdata:
CREATE TABLE PERSON AS
SELECT LEVEL AS ID, 'Person_'||LEVEL AS NAME, 10 as maxVal
FROM DUAL
CONNECT BY LEVEL <= 5;
create table orders as
SELECT LEVEL AS ID, 'Order_'||LEVEL AS NAME
FROM DUAL
CONNECT BY LEVEL <= 3;
If i try the following Query, i get only 3 Results instead of 5:
select p.*
from person p
where (maxVal - (select count(*)
from orders o
where o.id = p.id)
) > 0
If i modify the Query to the following, i get 5 Results (which should be the correct Number):
select p.*
from person p
where (maxVal - (select count(*)
from orders o
where o.id = p.id)
) > 1
Also the following modification delivers the correct Result:
select p.*
from person p
where (maxVal - (select count(*)
from orders o
where o.id = p.id)
) > 0 + 0
I also get the correct number of Results if i use Bind Variables:
select p.*
from person p
where (maxVal - (select count(*)
from orders o
where o.id = p.id)
) > :num
So, is there any (known) Bug if i use "greater than 0"?
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.
The order is of little consequence.
It (<>) is a function that is used to compare values in database table. != (Not equal to) functions the same as the <> (Not equal to) comparison operator.
In Oracle we can only put up to 1000 values into an IN clause.
It's a bug that came after another bug was patched.
("Bug 17564992 Wrong results with fix for bug 12999577 present My Oracle Support Doc ID 17564992.8")
It has it's own patch (Patch 17564992, we haven't tested) but there is a workaround (that we tested):
alter session set "_fix_control" = '12999577:0';
alter session set "_optimizer_squ_bottomup"= FALSE;
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