Oracle 存储过程 OUT 参数
Posted
技术标签:
【中文标题】Oracle 存储过程 OUT 参数【英文标题】:Oracle stored procedure OUT parameters 【发布时间】:2009-05-21 10:11:44 【问题描述】:我有一个带有 IN OUT 参数的存储过程,声明如下:
create or replace PROCEDURE RIFATT_SEGN0_INS(pIdRifattSegn0 in OUT NUMBER,
pNumDossier IN VARCHAR2 ,
pNumConsegna IN NUMBER,
pDtConsegna IN DATE,
[..]
) AS
[..]
每当我从另一个过程中调用它时,我如何获取也输出的 pIdRifattSegn0 参数?
【问题讨论】:
【参考方案1】:您的问题并不完全清楚。顾名思义,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.
问候, 抢。
【讨论】:
以上是关于Oracle 存储过程 OUT 参数的主要内容,如果未能解决你的问题,请参考以下文章