MySQL IS NOT NULL 和 != '' 之间的区别
MySQL有什么区别吗
IF (myText IS NOT NULL) THEN
MySQL和
IF (myText != '') THEN
Is there any difference between MySQL
IF (myText IS NOT NULL) THEN
and
IF (myText != '') THEN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,
NULL< 之间有很大区别/code>
值和空白/空值。
这是一个资源,描述了差异。
当
myText IS NULL
时:myText IS NOT NULL
计算结果为FALSE
myText != ''
计算结果为NULL
(本质上与您编写的特定情况下的FALSE
的行为相同)但是,您不应该养成以相同方式对待它们的习惯,因为大多数时候它们会行为不同:例如:
假设您有一个表
tbl
:注意: 1 包含
NULL
值,2 包含空字符串 (<代码>'')。如果您运行以下查询:
... 它将返回记录 3。
如果您运行以下查询:
... 它将返回记录 2 和 3。
Yes there is a big difference between a
NULL
value and a blank/empty value.Here's one resource that describes the differences.
When
myText IS NULL
: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:
Assume you have a table
tbl
:Note: 1 contains a
NULL
value, and 2 contains an empty string (''
).If you run the following query:
... it will return record 3.
If you run the following query:
... it will return records 2 and 3.
是的,有区别。
简而言之,myText IS NOT NULL 指定 myText 具有某个也可能是 '' 的值。
myText != '' 指定,如果 myText 不包含空字符串,则返回 TRUE。
Yes there is a difference.
In simple words, myText IS NOT NULL specifies that myText is having some value which could be '' too.
Where as myText != '' specifies that it returns TRUE, if myText does NOT contain an empty string.
有一个区别。如果某列的默认值为“NULL”,那么如果该字段没有设置任何数据,则该字段确实为空。但是,如果字段的值已更新为 '',则它不是 NULL,而是空。
请参阅此处了解更多信息链接
There is a difference. If the default value of a column is "NULL", then if no data has been set for a field, it is truly null. However, if the value of a field has been updated as '', it is not NULL, rather it is empty.
See here for more information Link