当前位置:Gxlcms > 数据库问题 > Oracle中不等于号问题

Oracle中不等于号问题

时间:2021-07-01 10:21:17 帮助过:52人阅读

 

测试SQL

create table test(
  id int,
  name varchar2(10),
  age int
)

insert into test(id,name,age) values(1,‘zhangsan‘,23);
insert into test(id,name,age) values(2,‘lisi‘,‘‘);
insert into test(id,name,age) values(3,‘wangwu‘,null);
insert into test(id,name,age) values(4,‘sunqi‘,27);
insert into test(id,name,age) values(5,‘‘,22);

如图:

技术分享

字段NAME和AGE都有空值

 

例1、查询AGE不等于23的数据

select * from test where  age <> 23;

技术分享

 

例2、查询NAME不为lisi的数据

select * from test where name != ‘lisi‘;

技术分享

 

以上两个例子严格意义上说均不符合我们的要求,因为没有把null值查询出来

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

 

最后正确的sql语句为:

select * from test where instr(concat(name,‘xx‘),‘lisi‘) = 0; --查询name字段不等于‘lisi‘的记录
或
select * from test where nvl(name,‘xx‘)<>‘lisi‘; 
select * from test where instr(concat(age,00),23) = 0; --查询age字段不等于23的记录
或
select * from test where nvl(age,00)<>23;


 作者:itmyhome


Oracle中不等于号问题

标签:oracle   不等于号   

人气教程排行