Oracle 生成工做日曆表

select to_char(everyDay, 'yyyy-mm-dd') as dt,
       to_char(everyday, 'yyyy') as yr,
       to_char(everyday, 'mm') as mm,
       to_char(everyday, 'dd') as dd,
       to_char(everyday, 'dy') as dayofweek,
       /*ORACLE自定義的標準周*/
       to_char(everyday, 'WW') as weeknum,
       /*該月的第幾周*/
       lpad(to_char(everyday, 'w'), 6) as monthOfWeek,
       /*所在季度*/
       to_char(everyday, 'Q') as qr,
       /*ISO的標準周,一般使用這個*/
       to_char(everyday, 'IW') as bourse_week,
       null as id
  from (select to_date('20190101', 'yyyymmdd') + level - 1 as everyDay
          from dual
        connect by level <= (last_day(to_date('20191201', 'yyyymmdd')) -
                   to_date('20190101', 'yyyymmdd') + 1));

結果圖:sql

 替換sql語句中的年份便可生成當年的數據。spa

相關文章
相關標籤/搜索