``in''子句在oracle中如何工作 [英] How does 'in' clause works in oracle

查看:55
本文介绍了``in''子句在oracle中如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select 'true' from dual where 1 not in (null,1);

当我们执行此操作时,不会产生任何结果

when we execute this which will result nothing

我的问题是什么

以上查询在逻辑上等同于

is the above query is logically equivalent to

select 'true' from dual where 1 != null and 1 != 1;

与上面的声明一样,不会产生任何结果

which will result nothing just as above statement

请澄清吗?

推荐答案

是正确的(但请注意,IN是运算符,而不是子句,并且通常在SQL中这样工作,不仅适用于Oracle).

Correct (but note that IN is an operator, not a clause and it works like this in SQL in general, not only for Oracle).

where 1 not in (null,1)

等效于:

where 1 != null and 1 != 1

它实际上应写为:

WHERE 1 NOT IN (NULL, 1)

WHERE 1 <> NULL AND 1 <> 1

与:

WHERE (1 <> NULL) AND (1 <> 1)

计算结果为:

WHERE UNKNOWN AND FALSE

,以及:

WHERE FALSE

因此,它正确不返回任何行.

So, it correctly returns no rows.

请注意,如果您拥有WHERE 1 NOT IN (NULL, 2),它将计算为WHERE UNKNOWN(作为练习),并且也不会返回任何行.

Notice that if you had WHERE 1 NOT IN (NULL, 2), it would evaluate to WHERE UNKNOWN (left as an exercise) and no rows would be returned either.

这篇关于``in''子句在oracle中如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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