空记录的搜索(求助)
lastdegree char null (可以为空)book 表中有lastdegree 字段空的记录100 条
现有以下二条SQL语句
1)
select count(*) from book where lastdegree=''
结果为: 0
2)
select count(*) from book where lastdegree IS null
结果为:100
请问以上二条语句什么不同...谢.. 空串“”和空值null是不同的,空串是一个长度为0的字符串,而空值null表示此数据没有值或不确定,所以null对应的操作符为is或is not而不是=、<、>等,并且任何2个null都是不相等的,即null <> null,但任何2个空串""都是相等的。
对于空值的操作或函数除了is和is not和count(*)的结果为真或假之外,其他的操作比如sum(),+,-,*,/,length()等操作结果皆为null,即空值。 要清楚char()是定长的记录,除非你插入的是null
where lastdegree = ''
和
where lastdegree = ' '
和
where lastdegree = ' ‘
都是一个结果,无论你加多少空格都一样。
匹配null的唯一办法就是指定 is null,不管是什么类型,什么数据库,都是如此。 3Q,谢谢各位大虾.
页:
[1]