【发布时间】:2016-11-23 10:49:05
【问题描述】:
我在 ORACLE 中输入以下 SQL 并通过:
select 1 from dual where 0=null;
为什么SQL通过了,没有编译错误看起来很奇怪。而且,如果null是表中的varchar2列,也会通过。
create table test
(
a varchar2(100),
b varchar2(100)
)
insert into test(a,b) VALUES (null, 'abc');
commit;
select * from test where a=0
更新:
因为a列是varchar2类型,0是数字类型,如果a不包含null,会报错。
create table test
(
a varchar2(100),
b varchar2(100)
)
insert into test(a,b) VALUES ('abc', 'abc');
commit;
select * from test where a=0
--ORA-01722 "invalid number"
谢谢。
【问题讨论】:
-
您对该查询有何期望?
-
“通过”是什么意思?
0 = null没有语法错误。它永远不会评估为真。 -
您的问题到底是什么?这里有什么意外?
-
这与
where 'foo' = 'bar'有何不同? -
@Bohemian:看来 OP 对编译错误、运行时错误和成功编译并执行但不返回任何内容的语句之间的区别感到困惑。请重新打开。