为什么 column = NULL 不返回任何行? [英] Why does column = NULL return no rows?

查看:62
本文介绍了为什么 column = NULL 不返回任何行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
为什么 NULL = NULL 在 SQL 服务器中计算为假

如果您生成查询以在MyTab"表中为列 --- Age、Sex、DOB、ID 插入数据

If you generate a query to insert the data in table "MyTab" for column --- Age, Sex, DOB, ID

INSERT INTO MyTab 
VALUES (22, '', '', 4)

Sex & 列中的值是多少?出生?是 NULL 吗?

What'll be the value in column Sex & DOB ? Is it NULL ?

如果值为 NULL 则 ---

If value is NULL then ---

 SELECT * FROM MyTab
 WHERE Sex=NULL

上面的查询给出输出----没有选择行---为什么??

above query gives output ---- no rows selected --- why ??

如果值不为 NULL 则 ---

if value is not NULL then ---

 SELECT * FROM Mytab
 WHERE Sex IS NULL

上面的查询给出了输出----如何??

above query gives the output ---- how ??

推荐答案

NULL 是 SQL 中的一个特殊值,表示缺少数据.因此,您不能执行以下查询:

NULL is a special value in SQL denoting the absence of data. As such, you cannot do queries like:

SELECT fields FROM table WHERE column = NULL

NULL 不能与任何东西进行比较,包括 NULL 本身.相反,您需要:

NULL cannot be compared to anything, including NULL itself. Instead, you'd need:

SELECT fields FROM table WHERE column IS NULL

<小时>

但是,在您的情况下,您实际上是在 SexDOB 中插入了一个空值.
空值不是NULL.您必须查询:


However in your case you are really inserting an empty value in Sex and DOB.
And empty value is not NULL. You'd have to query for:

SELECT fields FROM table WHERE column = ''

这篇关于为什么 column = NULL 不返回任何行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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