orcl between and 时间

在网上查阅,大家都说between and两边都会包含,但是对于时期来讲,他会包含前者,不会包含后者。

也就是说求一个时间介于上周六到本周五的区间,用between and 需要计算出上周六的时间和本周六的时间作为区间,如果以本周五的时间作为区间的话,

本周五的数据是无法获取的。

代码说明:

在表中创建了一条本周五的数据。

select (trunc(sysdate, 'D') - 1) upSaturday,  (trunc(sysdate, 'D') + 5) Friday ,(trunc(sysdate, 'D') + 6) Saturday from dual;

查出上周六、本周五、本周六时间作为参考。

select count(*) from zx_gzdb_report_content where create_time between (trunc(sysdate, 'D') - 1) and (trunc(sysdate, 'D') + 5);

第一次我们取区间上周六本周五得到的数据是0。

select count(*) from zx_gzdb_report_content where create_time between (trunc(sysdate, 'D') - 1) and (trunc(sysdate, 'D') + 6);

第二次我们取区间上周六本周六,可以获取本周五数据。

原文地址:https://www.cnblogs.com/ckxlovejava/p/7428847.html