我有一行满1,2,3和null.为什么没有两个返回相同的结果:
select * from foo where foobar not in (1, 2, 3);
select * from foo where foobar is not null;
Run Code Online (Sandbox Code Playgroud)
第一个返回空集,而第二个返回广告.现在我有点困惑:-D在任何地方都有某种"新手SQL中的NULL"文档吗?:-D
(我正在使用Oracle,如果这很重要)
这是因为您的第一个语句正在按如下方式进行评估:
select * from foo
where foobar <> 1 and foobar <> 2 and foobar <> 3
Run Code Online (Sandbox Code Playgroud)
"null <> 1"计算结果为null,而不是true/false,因此不返回任何内容.