SQL> select 1 from dual where not exists (select 1 from dual where 1=0);
1
----------
1
SQL> select 1 from dual where 1=0;
no rows selected
SQL> select 1 from dual where not exists (select max(1) from dual where 1=1);
no rows selected
SQL> select max(1) from dual where 1=1;
MAX(1)
----------
1
SQL> select 1 from dual where not exists (select max(1) from dual where 1=0);
no rows selected
SQL> select max(1) from dual where 1=0;
MAX(1)
----------
SQL> select 1 from dual where not exists (select null from dual);
no rows selected
SQL> select null from dual;
N
-
In the sub query there is a row but it is null, unknown. So not exists null evaluates to false. More about the issue in responses to a oracle-l mailing list post.
even
ReplyDeleteEXISTS (SELECT 1/0 FROM DUAL)
this is internal tuning ;)
SQL> select 1 from dual where exists (select 1/0 from dual);
ReplyDelete1
----------
1
SQL> select 1 from dual where not exists (select 1/0 from dual);
no rows selected