空运算符上的ALL运算符VS Any [英] ALL operator VS Any on an empty query

查看:103
本文介绍了空运算符上的ALL运算符VS Any的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 oracle ANY和ALL运算符上的文档.除了一件事,我非常了解它们的用途.它指出:

I'm reading the oracle documentation on the ANY and ALL operators. I pretty understand their uses except for one thing. It states:

全部:

如果子查询返回零行,则条件的计算结果为TRUE.

If a subquery returns zero rows, the condition evaluates to TRUE.

任何:

如果子查询返回零行,则条件的计算结果为FALSE.

If a subquery returns zero rows, the condition evaluates to FALSE.

对我来说,这似乎不太合逻辑.为什么在一个空子查询上的ALL将返回TRUE,而ANY返回FALSE?

It doesn't seem very logical to me. Why would ALL on an empty subquery would return TRUE but ANY returns FALSE?

我是SQL的新手,所以我假设它会有一个用例来说明这种行为,这对我来说确实是违反直觉的.

I'm relatively new to SQL, so I assume it would have a use-case for this behavior which is really counter-intuitive to me.

在空集上的任意和全部应该返回相同的值,不是吗?

ANY and ALL on an empty set should return the same value no?

推荐答案

因为将ANY解释为EXIST(如果存在,则表示它们存在).因此,如果未找到任何行,则返回false.

Because ANY is to be interpreted as EXIST (if there is any, it means they exist). Therefore, it return false if no rows are found.

All不能证明存在任何值,而只是证明它代表所有可能的值.因此,即使没有找到行,它也会返回true.

All does not certify that any values exist, it just certifies that it represents all possible values. Therefore, it return true even if no rows are found.

这篇关于空运算符上的ALL运算符VS Any的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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