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’) || ’