第四章 PL/SQL块使用 日历打印

这篇博客介绍了如何使用PL/SQL声明变量并编写代码来打印2018年任意月份的日历。通过转换星期为数字,计算出月的第一天是周几,确定月的最后一天,然后按照格式输出日历,包括日期和星期的布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

declare
v_year number := 2018;
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’) || ’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值