我有一个查询,当列值为null时,我不想在where条件下追加“和”子句。
select * from x where x.abc = 'ACTIVE' and x.start_date < sysdate and x.end_date > sysdate
因此,在这里,我希望x.end_date只有在它的值不是具有任何存储过程的null.Not的情况下才会应用,这只是一个简单的查询。
我还希望使用标准生成器和谓词将此查询转换为spring规范。
发布于 2018-06-05 03:42:11
您可以使用or
select *
from x
where x.abc = 'ACTIVE' and
x.start_date < sysdate and
( x.end_date > sysdate or x.end_date is null );
发布于 2018-06-05 03:44:24
您可以查看这方面的NVL功能。
select * from x
where x.abc = 'ACTIVE'
and x.start_date < sysdate
and NVL(x.end_date,sysdate) >= sysdate
发布于 2018-06-05 04:07:48
这并不是说其他的答案不正确,也不是很好,但我会把它写得有点不同,我把它放在这里,希望有人能对一种方式比另一种方法更好的原因有一个有趣的评论。
我要写的是:
select * from x
where x.abc = 'ACTIVE'
and sysdate between x.start_date and nvl(x.end_date,sysdate);
对我来说,那是:“当前日期必须在记录的活动日期范围内”。
https://stackoverflow.com/questions/50699214
复制相似问题