Bootstrap

oracle查询不等于条件包含null值

  1. 测试表

create table testN (id int);

 

insert into testN values(1);

insert into testN values(2);

insert into testN values(NULL);

 

commit;

 

 (2)查询id不等于2的数据

select * from testN where id<>2;

 

 可以发现查询结果集不包括id为null的值,所以想得到正确的结果集需要得到包括null的值,可以使用下面的查询方法。

方式1:

select * from testN where id<>2 OR ID IS NULL;

 

 方式2:使用滤空函数

SELECT * FROM testN WHERE NVL(ID,9999)<>2;

 

;