Ron*_*tro 5 sql oracle null clause where
WHERE子句可以返回NULL而不是TRUE或FALSE吗?根据下面的练习,它是可能的,但我无法想象一个返回NULL的例子,它真的可能吗?
4. Which of the following values can NOT be returned after evaluation of WHERE clause
condition?
A. UNKNOWN
B. TRUE
C. FALSE
D. NULL
Answer: A. If the result of the condition in WHERE clause is not known, NULL is returned. In all
other scenarios, either TRUE or FALSE is returned.
Run Code Online (Sandbox Code Playgroud)
在 SQL 中,所有逻辑运算符的计算结果为 TRUE、FALSE 和 UNKNOWN(Oracle 文档),在 MySQL 中 UNKNOWN 结果调用 NULL(MySQL 文档)。
根据oracle文档:
“要测试空值,请仅使用比较条件 IS NULL 和 IS NOT NULL。如果对空值使用任何其他条件并且结果取决于空值,则结果为未知。”
所以评估后只能返回 TRUE、FALSE 和 UNKNOWN。
关于你的问题:
“WHERE 子句可以返回 NULL 而不是 TRUE 或 FALSE 吗?”
严格来说,在 Oracle 中 -否,因为此类结果称为“未知”。
但一般来说,UNKNOWN 和 NULL 的含义在这种情况下是等效的,只是同一事物的不同名称。因此下面的 SQL 示例 ( a.a >= all) 评估为 UNKNOWN。
with table_a as (
select null as a from dual
union all
select 10 as a from dual
union all
select 5 as a from dual),
table_b as (
select null as a from dual
union all
select 10 as a from dual
union all
select 5 as a from dual)
select * from table_a a where a.a >= all(select a from table_b b)
Run Code Online (Sandbox Code Playgroud)