Oracle中不等號問題,oracle等號

來源:互聯網
上載者:User

Oracle中不等號問題,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;


 作者:itmyhome


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.