2010-11-03 59 views
3

这让我非常震惊。如何匹配DB2(z/OS)查询中的字符串?

我想要做的就是在长的varchar字段上进行基本字符串比较。

我有一个约表。 12M记录。

如果我查询MY_FIELD='a string',我得到了25947的计数,这似乎是正确的。

如果我查询MY_FIELD!='a string',我得到的989

计数不应该这两个数加起来12M的全表的大小?

回答

6

而这些行中有多少是MY_FIELD设为NULL

a. select count(*) from mytable; 
b. select count(*) from mytable where my_field is null; 
c. select count(*) from mytable where my_field is not null; 
d. select count(*) from mytable where my_field = 'some value'; 
e. select count(*) from mytable where my_field != 'some value'; 

NULL不等于或不等于任何价值,包括NULL所以我希望d+e等同于cb+c等同于a

+0

谢谢大家。这是问题!咄。 – m2green 2010-11-03 14:17:16