从过程变为另一个过程的参数

时间:2012-06-20 17:48:06

标签: oracle parameters plsql package procedure

使用包,如何将过程中的变量赋值传递给另一个过程的参数?

2 个答案:

答案 0 :(得分:2)

我不确定您是否想知道全局变量或OUT参数的工作原理。下面是使用过程的OUT参数的示例。有关使用IN和OUT的更多信息,请参见here

create or replace package TEST_PKG
IS
    procedure test(p_input IN NUMBER, p_output OUT NUMBER)
    IS
    BEGIN
        p_output := p_input * p_input;
    END test ;

    procedure testRun
    IS
        v_input NUMBER := 0;
        v_output NUMBER;
    BEGIN
        test(v_input, v_output);
        DBMS_OUTPUT.PUT_LINE('OUTPUT : ' || v_output );
    END test ;
END xyz;

答案 1 :(得分:1)

create or replace package xyz
IS
  procedure test 
  IS
   v_temp varchar2(20); --local variable
  BEGIN
    v_temp:=20; --assigning value to a variable

  --if procedure is within the same package,as this example shows ,then call as below  
  test2(v_temp);

  --if procedure is in another package say PQR then call as below,
  --but the procedure should be declared in the specification of the package PQR
  PQR.test2(v_temp);  

  --if procedure is not inside any package ,just a single procedure is there
  --,then call as below
  test2(v_temp);

   END test ;

   procedure test2(p_temp IN varchar2)
   IS
   BEGIN
   --do you processing
   END test2;
 END xyz;

希望这有帮助