浅析Oracle中的不等于号

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浅析Oracle中的不等于号相关的知识,希望对你有一定的参考价值。

参考技术A 关于Oracle中的不等于号:
在Oracle中,
<>
!=
~=
^=
都是不等于号的意思。都可以使用。
但是奇怪是的,
我想拿出price不是180000的商品时:(price是Number类型的)
SELECT
id,
name
FROM
product
where
price<>
180000;
执行这个语句时,priceis
null
的记录不出来。也就是拿不到price是null的商品。必须使用:
SELECT
id,
name
FROM
product
where
price<>
180000
or
price
is
null;才行。
字符串的字段存在同样的问题。
记住:null只能通过is
null或者is
not
null来判断,其它操作符与null操作都是false。
==============================================================
测试:select
*
from
test
where
name<>'xn'。只能查出name非空的记录。去掉name<>'xn'就可以了。这种写法有问题。
然后用了instr(name,'xn')=0
来判断,如果name非空的话,判断还是有效的。如果name为空,这个判断又出问题了。不得已只得采取instr(concat(name,'xx'),'xn')
=
0来判断,因为就算name为空,当和'xx'连接后,也会不为空的。
所以最后的sql语句为:
select
*
from
test
where
instr(concat(name,'xx'),'xn')
=
0
来查询name字段不等于'xn'的记录。
或者可以用
select
*
from
test
where
nvl(name,'xx')<>'xn'
来查询name字段不等于'xn'的记录。

oracle不等于号怎么表示

在Oracle中,
<>
!=
~=
^=
都是不等于号的意思。都可以使用。
但是奇怪是的, 我想拿出price不是180000的商品时:(price是Number类型的)
SELECT id, name FROM product where price<> 180000;
执行这个语句时,priceis null 的记录不出来。也就是拿不到price是null的商品。必须使用:
SELECT id, name FROM product where price<> 180000 or price is null;才行。
字符串的字段存在同样的问题。
记住:null只能通过is null或者is not null来判断,其它操作符与null操作都是false。
测试:select * from test where name<>\'xn\'。只能查出name非空的记录。去掉name<>\'xn\'就可以了。这种写法有问题。
然后用了instr(name,\'xn\')=0 来判断,如果name非空的话,判断还是有效的。如果name为空,这个判断又出问题了。不得已只得采取instr(concat(name,\'xx\'),\'xn\') = 0来判断,因为就算name为空,当和\'xx\'连接后,也会不为空的。
所以最后的sql语句为:
select * from test where instr(concat(name,\'xx\'),\'xn\') = 0 来查询name字段不等于\'xn\'的记录。
或者可以用 select * from test where nvl(name,\'xx\')<>\'xn\' 来查询name字段不等于\'xn\'的记录。
参考技术A 不等于号用<>或者!=都可以。

以上是关于浅析Oracle中的不等于号的主要内容,如果未能解决你的问题,请参考以下文章

Oracle中奇怪的不等于号

Oracle如何查询不等于某数值

oracle 不等于1怎么查?

JAVA 的不等于语句怎么写

MySQL查询语句的不等于怎么写

java中的不等于怎么表示呀