oracle制作月历,Oracle plsql 月历

declare

v_year number := 2013;

v_month number := &input_month;

v_day number;

v_lastday number;

begin

dbms_output.put_line(v_year || '年' || v_month || '月的月历');

--转换星期为数字,方便计算

case substr(to_char(to_date(v_year || v_month,'yyyymm'),'day'),3,1)

when '日' then v_day := 1;

when '一' then v_day := 2;

when '二' then v_day := 3;

when '三' then v_day := 4;

when '四' then v_day := 5;

when '五' then v_day := 6;

when '六' then v_day := 7;

else null;

end case;

v_lastday := to_char(last_day(to_date(v_year || v_month,'yyyymm')),'dd');

dbms_output.put_line('第一天为本周第' || v_day || '天');

dbms_output.put_line('本月共' || v_lastday || '天');

dbms_output.put_line(' 日  一  二  三  四  五  六');

--PS:以上所有要用到的数据都已经得到了,下面是展示

--缩进月的第一天

for j in 1 .. v_day - 1 loop

dbms_output.put('    ');

end loop;

--顺序打印每天

for i in 1 .. v_lastday loop

dbms_output.put(to_char(i,'99') || ' ');

--如果遇到星期六,则换行(保证星期的标识从1-7循环)

if v_day = 7 then

dbms_output.put_line('');

v_day := 1;

else

v_day := v_day + 1;

end if;

end loop;

--PS:空格在打印的时候,可能被省略,可以换成其他字符尝试

--输出最后一行未能输出的字符

dbms_output.put_line('');

end;

效果如下:

2013年2月的月历第一天为本周第6天本月共28天 日 一 二 三 四 五 六 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值