为什么 null not in(1,2,3) false [英] Why is null not in(1,2,3) false

查看:57
本文介绍了为什么 null not in(1,2,3) false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否预期当我测试空值是否在列表中时,结果始终为假.

Is it expected that when I test if a null value is not in a list, the result is always false.

即:

 select 'Hello world' where null not in(1,2,3);

不要选择任何东西,因为 null not in(1,2,3) 是假的.

Don't select anything, because null not in(1,2,3) is false.

我不明白这一点,因为列表(1,2,3) 不包含任何未定义的值(null),所以我希望null not in(1,2,3) 为真.那为什么是假的呢?

I don't understand this, because the list(1,2,3) don't contain any undefined values(null) so I would expect the null not in(1,2,3) to be true. So why is it false?

推荐答案

实际上 null not in (1,2,3) 返回 null,而不是 false,但它就像 false 一个 where 子句(因为它不是 true).

Actually null not in (1,2,3) returns null, not false, but it works like false a where clause (since it's not true).

空比较 (a = null) 等总是返回 null,并且因为 null 不在 (1,2,3)本质上是一样的:

Null comparisons (a = null), etc. always return null, and since null not in (1,2,3) is essentially the same as:

NOT (null = 1 OR null = 2 OR null = 3)

返回值为 null.最好的办法是进行显式空检查并分别处理这些情况.

The return value will be null. Your best bet is to do explicit null checks and handle those cases separately.

旁注:NULL in (null, 1, 2, 3) 也会返回 null ,因为 null = null 返回 null.

Side note: NULL in (null, 1, 2, 3) will return null as well since null = null returns null.

这篇关于为什么 null not in(1,2,3) false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆