to pos7445: 你这样插入的是一个空格,不是空字符串。空字符串是不包含任何字符的字符串,但是由于有确定的值,所以不是NULL。它可以和其他字符串一样参加运算,并且是任何非NULL字符串的子串。
Nulls"If a column in a row has no value, then the column is
said to be null, or to contain a null. Nulls can appear in columns of any datatype that are not restricted by NOTNULL or PRIMARY KEY integrity constraints. Use a null when the actual value is not known or when a value would not be meaningful.Do not use null to represent a value of zero, because they are not equivalent. (Oracle currently treats a character value with a length of zero as null. However, thismay 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 anull 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."
f.e. update student set student_name = 'null' where student_name is null
to 大象: 我的理解是这样的:假设有个字符串指针,若值为nil,则对应的字符串为Null,若指针指向一个合法的字符串,但第一个字符就是\0,则字符串为空字符串。或者类似于MS SQL Server 中的处理方法,紧邻的两个单引号表示空串。 我感觉空串是有确定的值的,而Null是没有确定的值的。两个空串相等,两个Null却不相等。 我之所以不愿意使用Null,是因为怕麻烦。Null和普通值不能等同处理,否则容易出错,所以每个地方都要单独判断空值,太麻烦了。
said to be null, or to contain a null. Nulls can appear in columns of any
datatype that are not restricted by NOTNULL or PRIMARY KEY integrity
constraints. Use a null when the actual value is not known or when a value
would not be meaningful.Do not use null to represent a value of zero,
because they are not equivalent. (Oracle currently treats a
character value with a length of zero as null. However, thismay 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 anull 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."
update student set student_name = 'null' where student_name is null
NULL也可以运算,'abc'||NULL = 'abc'
但是需要知道2*NULL=NULL
可以用NVL(field,urvalue)如果是空,则指定别的值
如select nvl(field,'') from table --如果是NULL,则转换为''
在程序中,可以用ISNULL(rs("field"))这样的函数来处理(VB)。
我觉得讨论了这么多,要么你就把''当作NULL来处理,
要么你就把''重新标记为别的标志。起码现在在oracle没有好的处理办法可以插入一个''有认成一个''
但判断是否为非空字符串的时候,需要用trim(str)先trim掉如果trim(str) is null,则此str当作''来处理,其它的按照字符串处理。
我的理解是这样的:假设有个字符串指针,若值为nil,则对应的字符串为Null,若指针指向一个合法的字符串,但第一个字符就是\0,则字符串为空字符串。或者类似于MS SQL Server 中的处理方法,紧邻的两个单引号表示空串。
我感觉空串是有确定的值的,而Null是没有确定的值的。两个空串相等,两个Null却不相等。
我之所以不愿意使用Null,是因为怕麻烦。Null和普通值不能等同处理,否则容易出错,所以每个地方都要单独判断空值,太麻烦了。
所以,你可以用 penitent(只取一瓢) 提到的函数nvl,
这样的话,在自己的程序里面是不用判断是不是空的!
可以直接使用。
获取到记录以后,可能要做运算,也可能要使用值;用户编辑后,可能要判断,也可能要插入数据库。在这些地方,Null和字符串的处理不同,如果都当作字符串处理就会出错。
如果用Null的话,就要特别照顾了。