MySQL IS NOT NULL和!=之间的区别 [英] Difference between MySQL IS NOT NULL and != ''

查看:177
本文介绍了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 to FALSE
  • myText != '' evaluates to NULL (which essentially behaves the same as FALSE 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屋!

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