千家信息网

2011-10-14 对变量的引用

发表于:2024-12-01 作者:千家信息网编辑
千家信息网最后更新 2024年12月01日,http://www.itpub.net/thread-1499223-5-1.html46 楼星期一我写了这个存储过程:CREATE OR REPLACE PROCEDURE plch_show_a
千家信息网最后更新 2024年12月01日2011-10-14 对变量的引用

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)ISBEGIN   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.45PL/SQL procedure successfully completedSQL>

(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.77PL/SQL procedure successfully completedSQL>

(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.77PL/SQL procedure successfully completedSQL>

(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.45PL/SQL procedure successfully completedSQL>


答案BC

http://www.itpub.net/thread-1499223-6-1.html 52楼

Steven 建议你仔细审查在内嵌子过程里对全局变量、自身参数的引用情况。在很多情况下,最好把内嵌子过程转移出来,便于代码共享和调试。


知识点后补

0