您好,登錄后才能下訂單哦!
http://www.itpub.net/thread-1499223-5-1.html
46 樓
星期一我寫了這個存儲過程:
CREATE OR REPLACE PROCEDURE plch_show_amounts ( amount1_in IN NUMBER , amount2_in IN NUMBER) IS BEGIN DBMS_OUTPUT.put_line ( TO_CHAR (plch_show_amounts.amount1_in, 'FML999G999D99')); DBMS_OUTPUT.put_line ( TO_CHAR (plch_show_amounts.amount2_in, 'FML999G999D99')); END; /
星期二,我有個同事覺得自己比任何人都知道該如何寫好代碼,他批評過程中出現的重復代碼。“你為什么不把重復的代碼放到一個嵌套的子過程?那樣的話,假如你需要修改顯示格式,或者其他和顯示金額相關的東西,你只需修改一個地方。”
好吧,我也沒法反對。所以我把代碼移入一個嵌套的子過程。實際上,我在推出一個能使用的程序版本之前也這么干過幾次。
下面的選項中哪些包含了一個對原始的plch_show_amounts的“重構”,從而在我執行這段代碼之后:
BEGIN plch_show_amounts (100.45, 452666.77); END; /
我在屏幕上會看到這樣的輸出:
$100.45 $452,666.77
(A)
CREATE OR REPLACE PROCEDURE plch_show_amounts ( amount1_in IN NUMBER , amount2_in IN NUMBER) IS PROCEDURE show_one (amount_in IN NUMBER) AS BEGIN DBMS_OUTPUT.put_line ( TO_CHAR (amount1_in, 'FML999G999D99')); END; BEGIN show_one (plch_show_amounts.amount1_in); show_one (plch_show_amounts.amount2_in); END; /
SQL> BEGIN 2 plch_show_amounts (100.45, 452666.77); 3 END; 4 / ¥100.45 ¥100.45 PL/SQL procedure successfully completed SQL>
(B)
CREATE OR REPLACE PROCEDURE plch_show_amounts ( amount1_in IN NUMBER , amount2_in IN NUMBER) IS PROCEDURE show_one (amount_in IN NUMBER) AS BEGIN DBMS_OUTPUT.put_line ( TO_CHAR (amount_in, 'FML999G999D99')); END; BEGIN show_one (plch_show_amounts.amount1_in); show_one (plch_show_amounts.amount2_in); END; /
SQL> BEGIN 2 plch_show_amounts (100.45, 452666.77); 3 END; 4 / ¥100.45 ¥452,666.77 PL/SQL procedure successfully completed SQL>
(C)
CREATE OR REPLACE PROCEDURE plch_show_amounts ( amount1_in IN NUMBER , amount2_in IN NUMBER) IS PROCEDURE show_one (amount1_in IN NUMBER) AS BEGIN DBMS_OUTPUT.put_line ( TO_CHAR (amount1_in, 'FML999G999D99')); END; BEGIN show_one (plch_show_amounts.amount1_in); show_one (plch_show_amounts.amount2_in); END; /
SQL> BEGIN 2 plch_show_amounts (100.45, 452666.77); 3 END; 4 / ¥100.45 ¥452,666.77 PL/SQL procedure successfully completed SQL>
(D)
CREATE OR REPLACE PROCEDURE plch_show_amounts ( amount1_in IN NUMBER , amount2_in IN NUMBER) IS PROCEDURE show_one (amount1_in IN NUMBER) AS BEGIN DBMS_OUTPUT.put_line ( TO_CHAR (plch_show_amounts.amount1_in, 'FML999G999D99')); END; BEGIN show_one (plch_show_amounts.amount1_in); show_one (plch_show_amounts.amount2_in); END; /
SQL> BEGIN 2 plch_show_amounts (100.45, 452666.77); 3 END; 4 / ¥100.45 ¥100.45 PL/SQL procedure successfully completed SQL>
答案BC
http://www.itpub.net/thread-1499223-6-1.html 52樓
Steven 建議你仔細審查在內嵌子過程里對全局變量、自身參數的引用情況。在很多情況下,最好把內嵌子過程轉移出來,便于代碼共享和調試。
知識點后補
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。