oracle 不等于1怎么查?

   更新日期:2024.04.17

查找方法如下:

空值null比较特殊,它不能通过=或者<>进行查询,只能用is null或者is not null进行查询,例如你的数据中有null值,那么用 字段名=1,字段名<>1,字段名=null都不能把这条数据检索出来,只有字段名 is null能检索出来。
所以需要查询的数据有两种,为null的,或者不等于1的,转化为sql就是
select * from 表 where 字段名 is null or 字段名 <> 1。



可以选择先查询全表,再查询字段=1的,两者做差集,sql为
select * from 表
minus
select * from 表 where 字段名=1

空值null比较特殊,它不能通过=或者<>进行查询,只能用is null或者is not null进行查询,例如你的数据中有null值,那么用 字段名=1,字段名<>1,字段名=null都不能把这条数据检索出来,只有字段名 is null能检索出来。
所以你需要查询的数据有两种,为null的,或者不等于1的,转化为sql就是
select * from 表 where 字段名 is null or 字段名 <> 1

假如你要查询A表,由于空值不能判断,固需要把空值进行转换

select * from A where nvl(number,10)<>1;
希望帮到你!

select * from tab1 where num is null or num <> 1;

==附
create table tab1(id number,num number); -- 创建表
--插入测试数据
insert into tab1 values(1,1);
insert into tab1 values(2,2);
insert into tab1 values(3,null);
select * from tab1 where num is null or num <> 1;

相关链接

欢迎反馈与建议,请联系电邮
2024 © 视觉网