8

我需要生成两个给定日期之间的所有日期。只要只有一个日期范围,它就可以正常工作。但是,如果我有多个日期范围,则此解决方案不起作用。我已经在这里和 asktom 上搜索过,但找不到相关的指针/解决方案。

我使用 all_objects 和 CONNECT BY ROWNUM 尝试了这两种解决方案,但没有运气。这是问题陈述:sqlfiddle

输入

ID  START_DATE      END_DATE 
101 April, 01 2013  April, 10 2013 
102   May, 10 2013    May, 12 2013

输出

ID  Dates
101 April, 01 2013 
101 April, 02 2013  
101 April, 03 2013  
101 April, 04 2013  
101 April, 05 2013  
101 April, 06 2013  
101 April, 07 2013  
101 April, 08 2013  
101 April, 09 2013  
101 April, 10 2013  
102   May, 10 2013  
102   May, 11 2013  
102   May, 12 2013
4

4 回答 4

8
select 
  A.ID, 
  A.START_DATE+delta dt
from 
  t_dates A, 
  (
     select level-1 as delta 
     from dual 
     connect by level-1 <= (
       select max(end_date - start_date) from t_dates
     )
  )
where A.START_DATE+delta <= A.end_date
order by 1, 2
于 2013-04-25T06:26:40.673 回答
4

请试试:

select 
  distinct ID, 
  START_DATE+level-1 DATES
from dual a, TABLE_DATES b
connect by level <= (END_DATE-START_DATE)+1
order by ID;
于 2013-04-25T06:28:43.410 回答
1
    select g.cycle_dt
        from 
            (select to_date(d,'DD-MM-YYYY') cycle_dt
               from dual
                    model
                    dimension by (trunc(to_date('30092015', 'DDMMYYYY')) d) 
                    measures (0 y)
                    rules (
                    y[for d from trunc(to_date('30092015', 'DDMMYYYY')) to to_date('30102015', 'DDMMYYYY')  increment 1]=0
                    )) g
        order by g.cycle_dt;
于 2015-05-21T16:56:02.680 回答
0
WITH NUMS AS (
  SELECT LEVEL-1 DaysToAdd
  FROM DUAL
  CONNECT BY LEVEL <= (
    SELECT MAX(END_DATE - START_DATE + 1)
    FROM HOLIDAY)
)
SELECT START_DATE + DaysToAdd DATE_TIME, DESCRIPTION, IS_SCHOOL_HOLIDAY, UPDATE_BY, CREATE_DATE
FROM HOLIDAY
CROSS JOIN NUMS
WHERE HOLIDAY.END_DATE - HOLIDAY.START_DATE  > DaysToAdd
ORDER BY 1, 2;
于 2019-11-22T06:53:58.140 回答