如何在Oracle DB中获取未来12天的数据

问题描述

比方说,今天是8月26日... 接下来的12天仅C,D

您能告诉我sql吗?

SELECT *,(与SAMPLES的区别),其中launch_date>(双精度的SELECY SYSDATE)???

谢谢GMB ... 我可以再问一个问题吗?

  • 在这种情况下,差异应为12。 结果应该是..
C,2020-09-07 05:23:33,12
D,2020-09-07 11:14:33,12

我尝试使用DATEDIFF。但是发生了ORA-00904。

Samples(table name)
name,launch_date

A,2020-09-05 11:33:33
B 2020-09-06 02:34:33
C 2020-09-07 05:23:33
D 2020-09-07 11:14:33
E 2020-09-08 08:13:33

解决方法

我知道您想要launch_date属于今天后第12天的行。

如果是这样,请考虑:

select * 
from samples 
where 
    launch_date >= trunc(sysdate) + interval '12' day
    and launch_date < trunc(sysdate) + interval '13' day

where子句可以简化如下:

where 
    launch_date >= trunc(sysdate) + 12
    and launch_date < trunc(sysdate) + 13
,

您可以在下面的简单查询中使用

SELECT * from SAMPLES where trunc(launch_date) between trunc(sysdate) and trunc(sysdate)+12;