Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible Oracle Bug with "greater than 0" in where Clause

Tags:

sql

select

oracle

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"?

like image 634
bernhard.weingartner Avatar asked Aug 22 '14 09:08

bernhard.weingartner


People also ask

How do you pass more than 1000 values in clause?

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.

Does order of WHERE clause matter in Oracle?

The order is of little consequence.

What does <> mean in Oracle?

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.

What is the limit of in clause in Oracle?

In Oracle we can only put up to 1000 values into an IN clause.


1 Answers

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;
like image 94
Varró Dávid Avatar answered Oct 01 '22 13:10

Varró Dávid