本文主要是介绍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 所在周
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31369373/viewspace-2127225/,如需转载,请注明出处,否则将追究法律责任。
这篇关于oracle 制作日历表,创建本月日历,创建某一个日历的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!