空场上的标准(Where Criteria on empty field)

编程入门 行业动态 更新时间:2024-10-26 18:25:25
场上的标准(Where Criteria on empty field)

考虑我有一个表格计划,其中包含以下值。

planName(VARCHAR2) | validFrom(timestamp) | validTo(timestamp) --------------------------------------------------------------- planA | 20-10-2013 |

我应该在'validTo'字段上使用where条件写入什么选择查询,以便即使在'validTo'中值为空也可以获取该行

例如,如果我写的查询如下: -

select * from plan where validFrom > to_Date('20-10-2013', 'DD-MM,YYYY') and validTo < to_Date('31-12-2029', 'DD-MM,YYYY')

并获得结果

planName(VARCHAR2) | validFrom(timestamp) | validTo(timestamp) --------------------------------------------------------------- | |

但是我也需要获取那一行。

Consider I have a table Plan with following values.

planName(VARCHAR2) | validFrom(timestamp) | validTo(timestamp) --------------------------------------------------------------- planA | 20-10-2013 |

What select query should I write with a where criteria on 'validTo' field so that to obtain that row even if the value is empty in 'validTo'

for Example, if I write the query like :-

select * from plan where validFrom > to_Date('20-10-2013', 'DD-MM,YYYY') and validTo < to_Date('31-12-2029', 'DD-MM,YYYY')

and obtaining result like

planName(VARCHAR2) | validFrom(timestamp) | validTo(timestamp) --------------------------------------------------------------- | |

but I need to fetch that row also.

最满意答案

谢谢我得到的每一个方法,希望这也会支持其他人。

select * from plan where COALESCE(validFrom , to_date('12/10/2799', 'DD/MM/YYYY')) > to_Date('20/10/2013', 'DD/MM/YYYY') AND COALESCE(validFrom , to_date('1/01/1700', 'DD/MM/YYYY'))< to_Date('31/12/2029', 'DD/MM/YYYY');

如果值为null,则COALESCE()将与下一个非空值进行比较。

COALESCE是NVL的替代方法。

Thanks every one I got the approach, hope this will support others too.

select * from plan where COALESCE(validFrom , to_date('12/10/2799', 'DD/MM/YYYY')) > to_Date('20/10/2013', 'DD/MM/YYYY') AND COALESCE(validFrom , to_date('1/01/1700', 'DD/MM/YYYY'))< to_Date('31/12/2029', 'DD/MM/YYYY');

If the value is null COALESCE() will compare with the next not null value.

COALESCE is an alternate approach to NVL.

更多推荐

本文发布于:2023-08-05 22:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1441432.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:场上   标准   Criteria   empty   field

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!