请帮我解决以下问题
我需要在另一个内部调用存储过程。内部SP将返回一个数字值,我需要将其存储在局部变量中。
粗略代码
AssignSpResult NUMBER;
AssignSpResult = SPtobecalled(Param1,Param2,OutParam);
这种语法很可能是错误的,所以请帮助纠正它
答案 0 :(得分:5)
以下是一个示例:
HR\XE> create or replace procedure Proc1(p_out out number)
2 is
3 begin
4 p_out := 123;
5* end;
HR\XE> /
Procedure created.
HR\XE> create or replace procedure Proc2
2 is
3 l_val number;
4 begin
5 Proc1(l_val);
6 dbms_output.put_line('Here is a value returned by Proc1: ' || to_char(l_val));
7 end;
8 /
Procedure created.
HR\XE> set serveroutput on;
HR\XE> exec Proc2;
Here is a value returned by Proc1: 123
PL/SQL procedure successfully completed
根据您的需要,使用函数返回数据的过程处理结果可能更方便。这是一个例子:
HR\XE> create or replace function F1 return number
2 is
3 l_ret_value number;
4 begin
5 l_ret_value := 123;
6 return l_ret_value;
7 end;
HR\XE> /
Function created.
HR\XE> create or replace procedure Proc3
2 is
3 l_val number;
4 begin
5 l_val := F1;
6 dbms_output.put_line('Value returned by the F1 function: ' ||
To_Char(l_val));
7 -- Or
8 dbms_output.put_line('Value returned by the F1 function: ' || To_Char(F1));
9 end;
HR\XE> /
Procedure created.
HR\XE> set serveroutput on;
HR\XE> exec proc3;
Value returned by the F1 function: 123
Value returned by the F1 function: 123
PL/SQL procedure successfully completed.
HR\XE>
答案 1 :(得分:3)
存储过程不会返回IN,OUT或IN OUT参数的值。所以可能你需要打电话:
SPtobecalled(Param1,Param2, AssignSpResult );