Are there some restrictions in Oracle that disallows to have a WHERE
clause that compares value of column+(subquery count(*))
? If the subquery table is empty, count(*) doesn’t yield to zero in this scenario.
I expect this query
select * from Foo where (x+(select count(*) from SomeEmptyTable))>0
To be identical to
select * from Foo where x>0
But instead Oracle doesn’t return any results with the first query. In MySql the both queries return the same result selt.
My test SQL snippets:
create table Foo ( x int );
insert into Foo values ( 1 );
create table SomeEmptyTable ( x int );
I’m using Oracle Database 11g Enterprise Edition Release 11.2.0.4.0
UPDATE:
Or does the comparison to zero have some special meaning in this case?
Both
select * from Foo where (x+(select count(*) from SomeEmptyTable))>=0
and
select * from Foo where (x+(select count(*) from SomeEmptyTable))>-1
Returns 1 row as would be expected. Only when compared to >0 zero rows are returned.