SQL 中的 NULL 是什么? [英] What is NULL in SQL?

查看:52
本文介绍了SQL 中的 NULL 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 SQL 中 NULL 的值感到困惑.NULL 我认为是空的.

那么它是否会包含任何垃圾值或未知值,或者像整数中的 0 或字符中的空白?

解决方案

在简单的世界中,您可以说Null 不是数据值,而是未知值的标记.

因此,对 NULL 执行的任何数学运算都将导致 NULL.例如,

10 + NULL = NULL

同样,如果你用字符串进行字符串连接,你会得到:-

'String ' ||空||'串联' -- 结果为 NULL

因此您可以说 Null 的意思是不适用"或不知道":它与零 (0) 或任何其他默认值不同,但更重要的是,null 的处理方式与其他值完全不同SQL 中的值,因为它实际上没有值.

一个例子来解释当我们说NULL意味着UNKNOWN VALUE时的含义:

StudentName TestResultX 78一个 89乙 67空

<块引用>

所以你可以看到学生C在测试中得到了NULL分数.所以呢这是什么意思?

现在可以说学生没有参加考试,或者可能是学生的数据不可用.但这绝对不意味着学生得了 0(就好像你给学生分配了 0 那么这意味着学生出现在测试中并在测试中获得零分).我们只能说学生的数据是

UNKNOWN or NULL

I am confuse about what is the value of NULL in SQL. NULL I think is empty.

So will it contain any garbage value or unknown value or like 0 in integer or blank in character?

解决方案

In simple worlds you can say that Null is not a data value, but a marker for an unknown value.

So any mathematical operations performed on NULL will result in NULL. For example,

10 + NULL = NULL

Similarly if you do string concatenation with string you get:-

'String ' || NULL || 'Concatenation'   -- Result is NULL

So you can say that Null means either "not applicable" or "don't know": it is not the same as zero (0) or any other default value, but more importantly, null is treated quite differently from other values in SQL, because it literally has no value.

An example to explain what it means when we say that NULL means UNKNOWN VALUE:

StudentName TestResult
X             78
A             89
B             67
C             NULL

So you can see that the student C got NULL marks in the test. So what does that mean?

Now one can say that the student does not sit in the test or it may be that the student's data is not avaialable. But it definitely does not mean that the student got 0(as if you assign 0 to the student then it would mean that the student appeared in the test and got zero) marks in the test. All we can say that the data for the student is

UNKNOWN or NULL

这篇关于SQL 中的 NULL 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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