今天突然才发现,Oracle中的“不等于操作符”是忽略Null的。
比如,查询comm不等于的300的记录,我会理所当然地使用where comm != 300
预想会返回包含Null的不等于300的记录(意识里认为Null也是“不等于30”的其中一种情况)。
而实际上,它只返回不为Null且不等于300的记录,见如下测试。
使用SCOTT的公共数据测试:
--All data select * from scott.emp t; --Not equal 300(Not contain null) select * from scott.emp t where t.comm != 300; --Not equal 300(Does contain null) select * from scott.emp t where t.comm != 300 or t.comm is null;