Get the App
SLTechnology News&Howtos  ›  Database  › 

2011-10-14 references to variables

Shulou Source: shulou.com Published: 2022-06-01 05:18:13 10月03日 Update

Http://www.itpub.net/thread-1499223-5-1.html

46th floor

I wrote this stored procedure on Monday:

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;/

On Tuesday, a colleague of mine thought he knew better than anyone how to write good code, criticizing the repetitive code that occurred in the process. "Why don't you put the repeated code in a nested subprocess? that way, if you need to change the display format, or anything else related to the display amount, you only need to change one place."

Well, I can't object either. So I moved the code into a nested subprocess. In fact, I did this several times before I released a working version of the program.

Which of the following options contains a "refactoring" of the original plch_show_amounts, after I execute this code:

BEGIN plch_show_amounts (100.45, 452666.77); END;/

I will see this output on the screen:

$100.45 $452666.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 452666.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 452666.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 >

Answer BC

52nd floor of http://www.itpub.net/thread-1499223-6-1.html

Steven recommends that you carefully review the references to global variables and your own parameters in the embedded subprocess. In many cases, it is best to move the embedded subprocedures out to facilitate code sharing and debugging.

Make up the knowledge points.

Tags: Code procedure situation week variable original in that case thing global parameter just colleague place actual actually screen suggestion best format version Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno vpn Docker Apple