MySQL IS NOT NULL和!=之间的区别 [英] Difference between MySQL IS NOT NULL and != ''
本文介绍了MySQL IS NOT NULL和!=之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MySQL之间有什么区别
Is there any difference between MySQL
IF (myText IS NOT NULL) THEN
和
IF (myText != '') THEN
推荐答案
Yes there is a big difference between a NULL
value and a blank/empty value.
这是一个资源描述差异.
myText IS NULL
时:
-
myText IS NOT NULL
评估为FALSE
-
myText != ''
的计算结果为NULL
(在此特定情况下,其行为与FALSE
相同)
myText IS NOT NULL
evaluates toFALSE
myText != ''
evaluates toNULL
(which essentially behaves the same asFALSE
would in this specific case you wrote)
但是,您不应该养成对它们一视同仁的习惯,因为在大多数情况下,它们的行为方式会有所不同:例如:
However, you should not get into the habit of treating them the same, since most of the time they will behave differently: For example:
假设您有一个表tbl
:
id text
1 NULL
2
3 abc
注意:1包含NULL
值,2包含空字符串(''
).
Note: 1 contains a NULL
value, and 2 contains an empty string (''
).
如果您运行以下查询:
SELECT * FROM tbl WHERE text != ''
...它将返回记录3.
... it will return record 3.
如果您运行以下查询:
SELECT * FROM tbl WHERE text IS NOT NULL
...它将返回记录2和3.
... it will return records 2 and 3.
这篇关于MySQL IS NOT NULL和!=之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文