Oracle 查询null值记录的问题

查询employees中 commission 小于0.2的人,

select * from employees where commission_pct <0.2;

此查询条件有误, 无法查询出commission为null值的记录。

null只能通过is null或者is not null来判断,其它操作符与null操作都是false

修改查询条件:

1)select * from employees where commission_pct <0.2 or commission_pct is null;

2)select * from employees where NVL(commission_pct,0)<0.2;

NVL(expr1,expr2)

expr1:可为空的字段或者表达式。

expr2:null的替代值。

3)select * from employees where LNNVL(commission_pct>=0.2);

lnnvl用于某个语句的where子句中的条件,如果条件为true就返回false;如果条件为UNKNOWN或者false就返回true。该函数不能用于复合条件如AND, OR, or BETWEEN中

猜你喜欢

转载自sunwonder.iteye.com/blog/2195128