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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。