Null大于任何日期数据类型? [英] Is Null Greater Than Any Date Data Type?

查看:124
本文介绍了Null大于任何日期数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 DB2 中有此查询

SELECT * FROM SOMESCHEMA.SOMETABLE WHERE SYSDATE > @A

如果 SYSDATE NULL ,假设 @A @A 的任何值c $ c>和 SOMESCHEMA.SOMETABLE.SYSDATE 是一个日期数据类型?

If the SYSDATE is NULL, would it be greater than any value of @A, assuming that @A and SOMESCHEMA.SOMETABLE.SYSDATE is a Date data type?

请帮忙感谢提前。

推荐答案


另一个对比较可以包含NULL值的值进行比较的谓词是DISTINCT谓词。如果两列包含相等的非空值,则使用正常相等比较(COL1 = COL2)比较两列将为真。如果两列都为空,则结果将为false,因为null不会等于任何其他值,甚至不等于另一个空值。使用DISTINCT谓词,空值被认为是相等的。因此,如果两列都包含相等的非空值,并且当两列都为空值时,COL2不是COL2的DISTINCT将为true。

Another predicate that is useful for comparing values that can contain the NULL value is the DISTINCT predicate. Comparing two columns using a normal equal comparison (COL1 = COL2) will be true if both columns contain an equal non-null value. If both columns are null, the result will be false because null is never equal to any other value, not even another null value. Using the DISTINCT predicate, null values are considered equal. So COL1 is NOT DISTINCT from COL2 will be true if both columns contain an equal non-null value and also when both columns are the null value.

DB2 Null Handling

这意味着所有比较操作都将为false,因为您将某个未知值与某个值进行比较。所以无论你使用什么比较(只有IS NULL / IS NOT NULL操作可以正常工作!),它将是假的。

That means that all comparison operations will be false because you are comparing an unknown value to something. So no matter which comparison you use (only the IS NULL/IS NOT NULL operation do work!), it will be false.

如果你希望查询工作应该使用类似于

If you want the query to work you should use something like

SELECT * 
  FROM SOMESCHEMA.SOMETABLE 
 WHERE COALESCE(SYSDATE, TIMESTAMP_FORMAT('0001-01-01 23:59:59', 'YYYY-MM-DD HH24:MI:SS'))  > @A

这篇关于Null大于任何日期数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆