oracle sql语句组装的日历

/*
日历(wyj)
*/
with aa as(select rownum as tian,to_char(to_date(‘198212’||to_char(rownum,‘00’),‘yyyymmdd’),‘dy’) as week from dual
connect by rownum<=to_number(to_char(last_day(to_date(‘198212’,‘yyyymm’)),‘dd’))),
bb as(
select ‘星期一’ as 星期一,‘星期二’ as 星期二,‘星期三’ as 星期三,‘星期四’ as 星期四,‘星期五’ as 星期五,‘星期六’ as 星期六,‘星期日’ as 星期日 from dual
),
cc as(
select decode(replace(bb.星期一,aa.week,aa.tian),‘星期一’,’’,aa.tian) 一,
decode(replace(bb.星期二,aa.week,aa.tian),‘星期二’,’’,aa.tian) 二 ,
decode(replace(bb.星期三,aa.week,aa.tian),‘星期三’,’’,aa.tian) 三 ,
decode(replace(bb.星期四,aa.week,aa.tian),‘星期四’,’’,aa.tian) 四 ,
decode(replace(bb.星期五,aa.week,aa.tian),‘星期五’,’’,aa.tian) 五 ,
decode(replace(bb.星期六,aa.week,aa.tian),‘星期六’,’’,aa.tian) 六 ,
decode(replace(bb.星期日,aa.week,aa.tian),‘星期日’,’’,aa.tian) 日 ,rownum as rn
from bb,aa)
select a1.一,a2.二,a3.三,a4.四,a5.五,a6.六,a7.日 from
(select 一,rownum as rn from cc a1
where 一 is not null or (rownum=1 and 日 is not null)) a1

left join (select 二,rownum as rn from cc
where 二 is not null or (rownum=1 and 日 is not null)) a2 on a1.rn=a2.rn
left join (select 三,rownum as rn from cc
where 三 is not null or (rownum=1 and 日 is not null)) a3 on a2.rn=a3.rn
left join (select 四,rownum as rn from cc
where 四 is not null or (rownum=1 and 日 is not null)) a4 on a3.rn=a4.rn
left join (select 五,rownum as rn from cc
where 五 is not null or (rownum=1 and 日 is not null)) a5 on a4.rn=a5.rn
left join (select 六,rownum as rn from cc
where 六 is not null or (rownum=1 and 日 is not null)) a6 on a5.rn=a6.rn
left join (select 日,rownum as rn from cc
where 日 is not null or (rownum=1 and 日 is not null)) a7 on a6.rn=a7.rn
order by a7.rn;

后来在网上看到有个算法的日历,是真的厉害,我这个看看就行了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值