这难道是oracle的bug?

gisinfo 2009-06-01 03:39:34

select * from table where a=1 and b<>'中国';
查出的结果为什么为空?
在sqlserver是可以查出一条记录的



数据如下
a b
1
2 中国
...全文
128 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuyou001 2009-06-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 gisinfo 的回复:]
在sqlserver中这可以的又是为什么?
[/Quote]
sql server 与oracle 处理 null 的方式不一样!
刚开始还没想起来,在oracle 10g&9i编程艺术这书就有提过
wangsong145 2009-06-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 gisinfo 的帖子:]

select * from table where a=1 and b <>'中国';
查出的结果为什么为空?
在sqlserver是可以查出一条记录的


数据如下
a b
1
2 中国
[/Quote]
在oracle里应该这样写才行:
select * from table where a=1 and (b<>'中国' or b is null)
suncrafted 2009-06-02
  • 打赏
  • 举报
回复
在where 和一般函数中,null是不等于任何任何值,同时null<>null
在分组函数中 null=null,null不等于其他值
liggway 2009-06-02
  • 打赏
  • 举报
回复
只用过oracle,确实null会过滤掉,并且其他函数什么的也是,分组函数除外
阿三 2009-06-02
  • 打赏
  • 举报
回复
SQL> select * from t_04 where a=1 and (b<>'中国' or b is null);

A B
---------- ----------
1

oracle中的null处理与sqlserver会不一样
wflyxiaonian 2009-06-02
  • 打赏
  • 举报
回复
数据库的规范不一样 咱没那水平 找不到人家bug的
gisinfo 2009-06-02
  • 打赏
  • 举报
回复
在sqlserver中这可以的又是为什么?
inthirties 2009-06-01
  • 打赏
  • 举报
回复
[Quote=引用楼主 gisinfo 的帖子:]

select * from table where a=1 and b <>'中国';
查出的结果为什么为空?
在sqlserver是可以查出一条记录的


数据如下
a  b

2  中国
[/Quote]


a=1的记录 b是null或者是'' 所以b <> '中国' 返回是false, null字段只能用is null和is not null来判断.
inthirties 2009-06-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Robin_Ares 的回复:]
b <>null 和b=null结果一样,都是无记录
null代表不存在,何谈等不等
只能写is null 和 is not null

[/Quote]

正解
gisinfo 2009-06-01
  • 打赏
  • 举报
回复
select * from table where a=1 and (b <>'中国' or b is null);



我当然晓得可以通过这个语句找到我要的结果

我也晓得其实select * from table where b <>'中国'

查出的结果就不包括
a b
1
这一行

在和其他任何条件做与操作都是惘然



但是 在应用程序中我用这个sql(select * from table where a=1 and (b <>'中国' or b is null);

)的话逻辑关系就不对了

sleepzzzzz 2009-06-01
  • 打赏
  • 举报
回复
如楼上所说,oracle对null的处理与SQL Server是完全不一样的,不要把MS那边的一些概念照套过来。
robin_ares 2009-06-01
  • 打赏
  • 举报
回复
b <>null 和b=null结果一样,都是无记录
null代表不存在,何谈等不等
只能写is null 和 is not null
fuyou001 2009-06-01
  • 打赏
  • 举报
回复
b <>'中国'=> b is not null and b <>'中国' 学习
hhuxyb 2009-06-01
  • 打赏
  • 举报
回复
select * from table where a=1 and b <>'中国';
b <>'中国'=> b is not null and b <>'中国'
fuyou001 2009-06-01
  • 打赏
  • 举报
回复
我试了下,在oracle 9iR2里,还真是空

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧