NULL comparison won’t work

NULL values cannot be compared to any value, comparison operators such as equal (=), greater than (>), greater than (>=), less than (<), less than or equal (<=) and not equal to (!= <> ^=) will not produce the desired results. They won’t produce any error. The result will be UNKNOWN. Because null represents a lack of data, a null cannot be equal or unequal to any value or to another null. However, Oracle considers two nulls to be equal when evaluating a DECODE function

select * from dual where DUMMY =  NULL;  
select * from dual where DUMMY >  NULL;  
select * from dual where DUMMY >= NULL;  
select * from dual where DUMMY <  NULL;  
select * from dual where DUMMY <= NULL;  
select * from dual where DUMMY != NULL;  
select * from dual where DUMMY <> NULL;  
select * from dual where DUMMY ^= NULL;

The only way you can manage NULL right way is by evaluating it via IS NULL or  IS NOT NULL.

select * from dual where DUMMY IS NULL; 
select * from dual where DUMMY IS NOT NULL;

 

 

 

Leave a comment

Your email address will not be published. Required fields are marked *