gpt4 book ai didi

sql - 为什么 10/NULL 评估为空?

转载 作者:行者123 更新时间:2023-12-03 20:28:33 28 4
gpt4 key购买 nike

在 SQL 中,为什么 10/NULL 评估为 NULL(或未知)?例子 :

if((10/NULL) is NULL)
DBMS_OUTPUT.PUT_LINE("Null.");

然而, 1 = NULL作为比较被认为是错误的。不应该 10/NULL 也被视为 FALSE 吗?

我指的只是 SQL。不是任何 DBMS。它可能是重复的,但我不知道在搜索此查询时要放置哪些关键字。

最佳答案

Shouldn't 10/NULL also be considered as FALSE?



没有为什么:

Any arithmetic expression containing a null always evaluates to null. For example, null added to 10 is null. In fact, all operators (except concatenation) return null when given a null operand.



重点是我的,摘自 Oracle 手册: http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements005.htm#i59110

这是 SQL 标准所要求的。

编辑 ,因为问题一般是针对 RDBMS 的:

数据库服务器

When SET ANSI_NULLS is ON, an operator that has one or two NULL expressions returns UNKNOWN



Link to the the manual :

MySQL

An expression that contains NULL always produces a NULL value unless otherwise indicated in the documentation for a particular function or operator



Link to the manual

数据库2

if either operand can be null, the result can be null, and if either is null, the result is the null value



Link to the manual :

PostgreSQL

不幸的是,我在 PostgreSQL 手册中找不到这样一个明确的声明,尽管我确信它的行为是一样的。

警告:“(连接除外)”是仅限 Oracle 的非标准异常。 (空字符串和 NULL 在 Oracle 中几乎相同)。连接空值在所有其他 DBMS 中给出空值。

关于sql - 为什么 10/NULL 评估为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12565050/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com