/tupian/20230522/thread-1499223-5-1.html
昌寧ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!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; /
星期二,我有個同事覺得自己比任何人都知道該如何寫好代碼,他批評過程中出現(xiàn)的重復(fù)代碼。“你為什么不把重復(fù)的代碼放到一個嵌套的子過程?那樣的話,假如你需要修改顯示格式,或者其他和顯示金額相關(guān)的東西,你只需修改一個地方。”
好吧,我也沒法反對。所以我把代碼移入一個嵌套的子過程。實際上,我在推出一個能使用的程序版本之前也這么干過幾次。
下面的選項中哪些包含了一個對原始的plch_show_amounts的“重構(gòu)”,從而在我執(zhí)行這段代碼之后:
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
/tupian/20230522/thread-1499223-6-1.html 52樓
Steven 建議你仔細審查在內(nèi)嵌子過程里對全局變量、自身參數(shù)的引用情況。在很多情況下,最好把內(nèi)嵌子過程轉(zhuǎn)移出來,便于代碼共享和調(diào)試。
知識點后補