好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Oracle中不等于号问题

 

测试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   不等于号   

查看更多关于Oracle中不等于号问题的详细内容...

  阅读:29次