第四章 PL SQL塊使用 日曆列印

2021-08-21 21:35:23 字數 1390 閱讀 3399

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』) || 』 『);

--如果遇到星期六,則換行(保證星期的標識從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;

第四章 PL SQL基礎(下)

6 迴圈語句 1 基本迴圈 loop loop end loop a if.then方式跳出迴圈 b exit.when方式跳出迴圈 2 while迴圈 while expresstion loop end loop 3 for迴圈 for counter in reverse start valu...

第四章 繼承

一 為什麼要繼承 在物件導向中我們將具有很多重複內容的類中的內容提取出來,寫成乙個單獨的類 其他類只需要繼承就能取得這些功能,同時可以在自己類中寫入獨特的自定義方法 二 繼承語法 inte ce circle nsobject 繼承是在介面中定義的 冒號後的類名是要整合的類,nsobject 是co...

第四章 物件

三個特性 身份 型別 值 每個物件都有唯一的身份來標識自己,使用內建函式id 得到。例子 usr bin env python coding utf 8 a 32 print a b a print id a id b 結果 d python27 python.exe e workp python ...