程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> oralcesql創建指定時間段內的日歷信息

oralcesql創建指定時間段內的日歷信息

編輯:Oracle教程

oralcesql創建指定時間段內的日歷信息


創建 開始時間是2010 截止時間是2100的日歷表數據。

create table temp_calendar as select

   min(to_char(day, 'yyyymm')) month,
   to_char(min(decode(weekday, 1, day)) ,'dd') w_7,
   to_char(min(decode(weekday, 2, day)),'dd') w_1,
   to_char(min(decode(weekday, 3, day)),'dd') w_2,
   to_char(min(decode(weekday, 4, day)),'dd') w_3,
   to_char(min(decode(weekday, 5, day)),'dd') w_4,
   to_char(min(decode(weekday, 6, day)),'dd') w_5,
   to_char(min(decode(weekday, 7, day)),'dd') w_6
  from (select trunc(day,'yyyy') year,
day,
         month,
         decode(sign(rn - weekday), 1, week + 1, week) week,
         weekday,
         rn
       from (select day,
             to_char(day, 'mm') month,
             to_char(day, 'w') week,
             to_char(day, 'd') weekday,
             row_number() over(partition by to_char(day, 'mm'), to_char(day, 'w') order by day) rn
           from (select trunc(to_date('2008','yyyy'), 'yyyy') + level - 1 day
               from dual
              connect by rownum <= trunc(to_date('2101','yyyy'),'yyyy')-trunc(to_date('2008','yyyy'),'yyyy')))) a
  group by a.year,a.month, a.week
  order by a.year,a.month, a.week;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved