设为首页 加入收藏

TOP

Oracle中不等于号问题
2015-11-21 02:09:17 来源: 作者: 【 】 浏览:2
Tags:Oracle 等于 问题

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;



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇CentOS修改MySql数据库目录datadir 下一篇excel数据导入oracle

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: