创建数据库的时候,对某个字段定义了 NOT NULL,但是,在写入数据的时候,空字符串''
竟然也能写入成功。
有人能给我解释一下 NULL 和 NOT NULL 到底是什么意思呢?
创建数据库的时候,对某个字段定义了 NOT NULL,但是,在写入数据的时候,空字符串''
竟然也能写入成功。
有人能给我解释一下 NULL 和 NOT NULL 到底是什么意思呢?
以下是摘自 Oracle SQL Reference 的内容,供你参考。版本是11g Release 2。
If a column in a row has no value, then the column is said to be null, or to contain null. Nulls can appear in columns of any data type that are not restricted by NOT NULL or PRIMARY KEY integrity constraints. Use a null when the actual value is not known or when a value would not be meaningful. Oracle Database treats a character value with a length of zero as null. However, do not use null to represent a numeric value of zero, because they are not equivalent.
Note: Oracle Database currently treats a character value with a length of zero as null. However, this may not continue to be true in future releases, and Oracle recommends that you do not treat empty strings the same as nulls.
Any arithmetic expression containing a null always evaluates to null. For example, null added to 10 is null. In fact, all operators (except concatenation) return null when given a null operand.
3 回答1.7k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
2 回答1.4k 阅读✓ 已解决
3 回答1.1k 阅读✓ 已解决
2 回答1.3k 阅读✓ 已解决
1 回答1.3k 阅读✓ 已解决
1 回答1k 阅读✓ 已解决
空 (NULL) 值表示数值未知。空值不同于空白或零值。没有两个相等的空值。比较两个空值或将空值与任何其它数值相比均返回未知,这是因为每个空值均为未知。
在写入数据的时候,空字符串'' 也是一个确定的值,所以就算你定义了 NOT NULL 也可以被写入。