十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
/tupian/20230522/thread-1499223-5-1.html
昌宁ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信: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; /
星期二,我有个同事觉得自己比任何人都知道该如何写好代码,他批评过程中出现的重复代码。“你为什么不把重复的代码放到一个嵌套的子过程?那样的话,假如你需要修改显示格式,或者其他和显示金额相关的东西,你只需修改一个地方。”
好吧,我也没法反对。所以我把代码移入一个嵌套的子过程。实际上,我在推出一个能使用的程序版本之前也这么干过几次。
下面的选项中哪些包含了一个对原始的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
/tupian/20230522/thread-1499223-6-1.html 52楼
Steven 建议你仔细审查在内嵌子过程里对全局变量、自身参数的引用情况。在很多情况下,最好把内嵌子过程转移出来,便于代码共享和调试。
知识点后补