MySQL Mysql中NULL和空值的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24444518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:40:49  来源:igfitidea点击:

Difference between NULL and Blank Value in Mysql

mysqlsql

提问by Himanshu

I have to check for a value of a particular Column named RESULTis blank or not.

我必须检查名为特定列的值是否为RESULT空。

When I check with if RESULT IS NULL, the query failed, but When I checked RESULT='', it worked.

当我检查时if RESULT IS NULL,查询失败,但是当我检查时RESULT='',它起作用了。

What is difference between two.

两者有什么区别。

please explain.

请解释。

"UPDATE RLS_TP_2012_03 a, RLS_TP_2012_03 b SET a.COMMENT=b.COMMENT where b.TCODE='T1199' and  a.GROUPNAME='xyz' and a.HLABNO=b.HLABNO and a.RESULT =''; ";   
"UPDATE RLS_TP_2012_03 a, RLS_TP_2012_03 b SET a.COMMENT=b.COMMENT where b.TCODE='T1199' and  a.GROUPNAME='xyz' and a.HLABNO=b.HLABNO and a.RESULT is NULL; "

回答by Ricky

  1. NULLis an absence of a value. An empty string is a value, but is just empty. NULLis special to a database.

  2. NULLhas no bounds, it can be used for string, integer, date, etc. fields in a database.

  3. NULLisn't allocated any memory, the stringwith NULLvalue is just a pointer which is pointing to nowhere in memory. however, Empty IS allocated to a memory location, although the value stored in the memory is "".

  1. NULL是值的缺失。空字符串是一个值,但只是空的。NULL对数据库来说是特殊的。

  2. NULL已经没有界限,它可以用于stringintegerdate等字段在数据库中。

  3. NULL没有分配任何内存,stringwithNULL值只是一个指向内存中任何地方的指针。然而,Empty IS分配到了一个内存位置,尽管内存中存储的值为""

回答by paxdiablo

In tri-value logic, NULL should be used to represent "unknown" or "not applicable" An empty column should represent "known but empty".

在三值逻辑中,NULL 应该用于表示“未知”或“不适用” 空列应该表示“已知但为空”。

Some DBMS products don't follow this convention all the time but I consider them deficient. Yes, you know who you are, Oracle :-)

一些 DBMS 产品并不总是遵循这个约定,但我认为它们有缺陷。是的,你知道你是谁,甲骨文 :-)

In addition, while NULL can be put into any column type (ignoring not nullclauses for now), you cannot put an "empty" value into a non-character field (like integer).

此外,虽然 NULL 可以放入任何列类型(暂时忽略not null子句),但您不能将“空”值放入非字符字段(如integer)。

回答by Ron Hiner

Adding to @ricky, NULL can never equal NULL, but an empty string is always equal to an empty string. That's a huge difference when you are trying to match records.

添加到@ricky,NULL 永远不能等于 NULL,但空字符串总是等于空字符串。当您尝试匹配记录时,这是一个巨大的差异。

回答by Sameer

NULL in database systems - No value set for the field. A void

数据库系统中的 NULL - 没有为该字段设置值。避免

NULL (character) - A blank, an ASCII/Unicode character with no graphical representation. But it is present in code page as a character constant '\0' with a character value 0 or 000.

NULL(字符) - 一个空白,一个没有图形表示的 ASCII/Unicode 字符。但它作为字符常量 '\0' 出现在代码页中,字符值为 0 或 000。