Oracle中的null

测试数据:公司部分员工基本信息

现在需要查询出退休员工,查询SQL(年龄大于等于60的男性和年龄大于等于50的女性):

select *
  from person t
 where (t.sex = '1' and t.age >= 60)
    or (t.sex <> '1' and t.age >= 50);

由于数据录入不完整,存在以下两位员工:

5    62    钱**        65
6    67    孙**         62

导致查询结果为:

以上的例子说明:在oracle数据库中,null不满足等于'1',也不满足不等于'1',而''不满足等于'1',但满足不等于'1'。

另外一个in相关的例子:

select  t.* from person t where t.sex not in ('1');

查询结果:

not in 和 <> 类似,所以以后写SQL时,需要注意。

原文地址:https://www.cnblogs.com/Candies/p/5341817.html