天天看点

oracle 制作日历表,创建本月日历,创建某一个日历

with  t1 as

-- 给定一个日期

(select  to_date('2016-10-27','yyyy-mm-dd') as cur_date from dual),

t2 as  --  取月初

(select  trunc(cur_date,'mm') as  月初,add_months(trunc(cur_date,'mm'),1)as 下月初 from  t1),

t3 as   -- 枚举当月所有的天

(select  月初+ (level-1) as  日  from  t2

connect by level <=(下月初-月初) ),

-- 提取周信息

t4 as

(select  to_char(日,'iw') 所在周,

to_char(日,'dd') 日期,

to_number(to_char(日,'d')) 周几 from  t3)

select

max(case 周几 when  2  then  日期 end ) 周一,

max(case 周几 when  3  then  日期 end ) 周二,

max(case 周几 when  4  then  日期 end ) 周三,

max(case 周几 when  5  then  日期 end ) 周四,

max(case 周几 when  6  then  日期 end ) 周五,

max(case 周几 when  7  then  日期 end ) 周六,

max(case 周几 when  1  then  日期 end ) 周日

from  t4

group by 所在周

order by 所在周

oracle 制作日历表,创建本月日历,创建某一个日历

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31369373/viewspace-2127225/,如需转载,请注明出处,否则将追究法律责任。