Http://www.itpub.net/thread-1499223-5-1.html 46 楼 星期一我写了这个存储过程: CREATE OR REP
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 建议你仔细审查在内嵌子过程里对全局变量、自身参数的引用情况。在很多情况下,最好把内嵌子过程转移出来,便于代码共享和调试。
知识点后补
--结束END--
本文标题: 2011-10-14 对变量的引用
本文链接: https://lsjlt.com/news/49075.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0