2009-05-21 314 views
3

我曾與一個IN OUT參數的存儲過程聲明如下所示:Oracle存儲過程OUT參數

create or replace PROCEDURE RIFATT_SEGN0_INS(pIdRifattSegn0 in OUT NUMBER, 
          pNumDossier IN VARCHAR2 , 
          pNumConsegna IN NUMBER, 
          pDtConsegna IN DATE, 
[..] 

) AS 
[..] 

每當我從其他程序調用它,我如何得到pIdRifattSegn0參數也出來了?

回答

13

你的問題並不完全清楚。顧名思義,一個IN OUT參數將以雙向方式傳遞。這意味着它必須傳遞一個變量,而不是一個文字,並且你需要一個聲明塊來做到這一點。例如:

declare 
    l_segn number; 
begin 
    l_segn := 1; 
    -- procedure will have received value = 1 
    rifatt_segn0_ins(l_segn, 'x', 2, sysdate); 
    -- procedure may have changed value of l_segn from 1 to something else 
    dbms_output.put_line(l_segn); 
end; 
2

下面是一個例子:

SQL> create or replace PROCEDURE RIFATT_SEGN0_INS 
    2 (pIdRifattSegn0 IN OUT NUMBER 
    3 , pNumDossier IN  VARCHAR2 
    4 , pNumConsegna IN  NUMBER 
    5 , pDtConsegna IN  DATE 
    6 ) 
    7 as 
    8 begin 
    9 dbms_output.put_line(pNumDossier); 
10 dbms_output.put_line(to_char(pNumConsegna)); 
11 dbms_output.put_line(to_char(pDtConsegna,'yyyy-mm-dd')); 
12 pIdRifattSegn0 := sqrt(pIdRifattSegn0); 
13 end; 
14/

Procedure is aangemaakt. 

SQL> create or replace procedure another_procedure 
    2 as 
    3 l_IdRifattSegn0 number := 4; 
    4 begin 
    5 rifatt_segn0_ins 
    6 (pIdRifattSegn0 => l_IdRifattSegn0 
    7 , pNumDossier => '1A' 
    8 , pNumConsegna => 42 
    9 , pDtConsegna => sysdate 
10 ); 
11 dbms_output.put_line('from another_procedure: l_IdRifattSegn0 = ' || to_char(l_IdRifattSegn0)); 
12 end; 
13/

Procedure is aangemaakt. 

SQL> exec another_procedure 
1A 
42 
2009-05-21 
from another_procedure: l_IdRifattSegn0 = 2 

PL/SQL-procedure is geslaagd. 

問候, 羅布。