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

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

问题描述

我在 DB2

SELECT * FROM SOMESCHEMA.SOMETABLE WHERE SYSDATE > @A

如果 SYSDATENULL,它会大于 @A 的任何值,假设 @ASOMESCHEMA.SOMETABLE.SYSDATEDate 数据类型?

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) 比较两列将为真.如果两列都为 null,则结果将为 false,因为 null 永远不会等于任何其他值,甚至不等于另一个 null 值.使用 DISTINCT 谓词,空值被视为相等.因此,如果两列都包含相等的非空值并且两列都是空值,则 COL1 与 COL2 不相异.

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 空值处理

这意味着所有比较操作都将是错误的,因为您正在将未知值与某物进行比较.所以无论你使用哪种比较(只有 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天全站免登陆