生成介于开始日期和结束日期之间的日期 [英] Generate the dates in between Start and End Dates
本文介绍了生成介于开始日期和结束日期之间的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要生成两个给定日期之间的所有日期.这是问题说明:
I need to generate all dates in between two given dates. Here is the problem statement:
输入:
START_DATE END_DATE
---------- ----------
01-FEB-16 03-FEB-16
01-FEB-16 04-FEB-16
01-FEB-16 05-FEB-16
01-FEB-16 03-FEB-16
11-FEB-16 14-FEB-16
输出(开始日期和结束日期之间的所有日期):
Output (All dates between start date and end dates):
BETWEEN_START_AND_END
----------------------
01-FEB-16
02-FEB-16
03-FEB-16
04-FEB-16
05-FEB-16
11-FEB-16
12-FEB-16
13-FEB-16
14-FEB-16
推荐答案
尝试一下...我让您更改日期格式以适合您的日期...
Try this... I let you change date format to fit yours...
with tbl(start_date,
end_date) as
(select date '2016-02-01'
,date '2016-02-03'
from dual
union all
select date '2016-02-01'
,date '2016-02-04'
from dual
union all
select date '2016-02-01'
,date '2016-02-05'
from dual
union all
select date '2016-02-01'
,date '2016-02-03'
from dual
union all
select date '2016-02-11'
,date '2016-02-14'
from dual)
select distinct start_date + level - 1
from tbl
connect by start_date + level - 1 <= end_date
order by 1;
将输出
01/02/2016
02/02/2016
03/02/2016
04/02/2016
05/02/2016
11/02/2016
12/02/2016
13/02/2016
14/02/2016
这篇关于生成介于开始日期和结束日期之间的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文