不等于 <>!= NULL 运算符 [英] Not equal <> != operator on NULL

查看:65
本文介绍了不等于 <>!= NULL 运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下 SQL 中的以下行为吗?

Could someone please explain the following behavior in SQL?

SELECT * FROM MyTable WHERE MyColumn != NULL (0 Results)
SELECT * FROM MyTable WHERE MyColumn <> NULL (0 Results)
SELECT * FROM MyTable WHERE MyColumn IS NOT NULL (568 Results)

推荐答案

<> is Standard SQL-92;!= 是等价的.两者都评估值,其中 NULL 不是 - NULL 是一个占位符,表示没有值.

<> is Standard SQL-92; != is its equivalent. Both evaluate for values, which NULL is not -- NULL is a placeholder to say there is the absence of a value.

这就是为什么你只能使用 IS NULL/IS NOT NULL 作为这种情况的谓词.

Which is why you can only use IS NULL/IS NOT NULL as predicates for such situations.

此行为并非特定于 SQL Server.所有符合标准的 SQL 方言都以相同的方式工作.

This behavior is not specific to SQL Server. All standards-compliant SQL dialects work the same way.

注意:要比较您的值是否不为空,请使用IS NOT NULL,而要与not null 进行比较 值,您使用 <>'YOUR_VALUE'.我不能说我的值是否等于或不等于 NULL,但我可以说我的值是 NULL 还是 NOT NULL.我可以比较我的值是否不是 NULL.

Note: To compare if your value is not null, you use IS NOT NULL, while to compare with not null value, you use <> 'YOUR_VALUE'. I can't say if my value equals or not equals to NULL, but I can say if my value is NULL or NOT NULL. I can compare if my value is something other than NULL.

这篇关于不等于 &lt;&gt;!= NULL 运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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