The relationship between Oracle inequality sign and Null, the query result does not contain null

When encountering query problems, write SQL when where status =! 'Y',
The expected result is: Query the data whose status is not 'Y' (including null).

However, the reality is: query the data whose status is not 'Y', and not 'null'.

Example table: emp  
  
   emp_no         name    age     status     
    001 Tom 17 Y
    002           Sun      14       N
    003           Tom      15       
    004           Tom      12       N

--All date
select * from emp;

-- != 'Y' does not contain null (emp_no = 002, 004)
select * from emp where status != 'Y';

-- != 'Y' contains null (emp_no = 002, 003, 004)
select * from emp where status != 'Y' or status is null;

//In fact, it's not just the relationship between the "not equal sign" and Null, other operators are similar, but the particularity of the "not equal sign" usage scenario makes it easy for us to discover this feature.

//The reason is Null, the various conditions of Null can be found in the following Oracle documents:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements005.htm
http://www.cnblogs.com/nick-huang/p/3921605.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326569855&siteId=291194637