Oracle中不等於號問題

2021-12-29 21:12:34 字數 1171 閱讀 4883

在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的資料

以上兩個例子嚴格意義上說均不符合我們的要求,因為沒有把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中的不等於號 在oracle中,都是不等於號的意思。都可以使用。但是奇怪是的,我想拿出price不是180000的商品時 price是number型別的 select id,name from p...

oracle 不等於號和null問題

關於oracle中的不等於號 在oracle中,都是不等於號的意思。都可以使用。price是number型別的 select id,name from product where price 1000 price是number型別的 執行這個語句時,priceis null 的記錄不出來。也就是拿不...

mysql 不等於號寫法

mysql 不等於號寫法 mysql中用 與 都是可以的,但sqlserver中不識別 所以建議用 selece from table where id 101 sql 裡 符號 於 的區別 與 都是不等於的意思,但是一般都是用 來 不等於因為 在任何sql中都起作用 但是 在sql2000中用到,...