1. 程式人生 > >利用connect by rownum構造日期列表

利用connect by rownum構造日期列表

利用connect by rownum構造日期列表

select v_day_date

  from (select to_char(trunc(sysdate-30 , 'mm') + rownum - 1, 'yyyymmdd') v_day_date

          from dual

        connect by rownum <=

                   (trunc(sysdate ) - trunc(sysdate-30 , 'mm')) + 1) mm

 where mm.v_day_date >= '20170912'

   and mm.v_day_date <=

'20171012';

v_day_date

20170912

20170913

20170914

20170915

20170916

20170917

20170918

20170919

20170920

20170921

20170922

20170923

20170924

20170925

20170926

20170927

20170928

20170929

20170930

20171001

20171002

20171003

20171004

20171005

20171006

20171007

20171008

20171009

20171010

20171011

20171012

--按時間段來跑資料

declare

begin

for i in (

select v_day_date

 from (select to_char(trunc(sysdate-30 , 'mm') + rownum - 1, 'yyyymmdd')v_day_date

         from dual

       connect by rownum <=

                   (trunc(sysdate ) -trunc(sysdate-30 , 'mm')) + 1) mm

 where mm.v_day_date >= '20170912'

  and mm.v_day_date <= '20171012') loop

  pkg_level3_info.prc_d_mcht_active_day(i.v_day_date);

  pkg_level3_info.prc_d_team(i.v_day_date);

end loop;

end;

/