Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Is this a bug, or am I loosing it
Thanks for your responses. Looks like this is an expected behavior. The Oracle 10g rel 2 SQL reference manual says following.
If any item in the list following a NOT IN operation evaluates to null, then all rows evaluate to FALSE or UNKNOWN, and no rows are returned. For example, the following statement returns the string 'True' for each row:
SELECT 'True' FROM employees
WHERE department_id NOT IN (10, 20);
However, the following statement returns no rows:
SELECT 'True' FROM employees
WHERE department_id NOT IN (10, 20, NULL);
The preceding example returns no rows because the WHERE clause condition evaluates to:
department_id != 10 AND department_id != 20 AND department_id != null
Because the third condition compares department_id with a null, it results in an UNKNOWN, so the entire expression results in FALSE (for rows with department_id equal to 10 or 20). This behavior can easily be overlooked, especially when the NOT IN operator references a subquery.
Regards,
J
This is not a bug, it's because of the NULLs and precisely the reason why not in and not exists are not equivalent whereas in and exists are.
At 12:47 PM 2/1/2007, JayDBA wrote:
I am getting weird results from a NOT IN and NOT EXISTS query. Could this be because of NULL's or is it a bug? Regards
Wolfgang Breitling
Centrex Consulting Corporation
www.centrexcc.com
-- http://www.freelists.org/webpage/oracle-lReceived on Thu Feb 01 2007 - 15:08:01 CST
![]() |
![]() |