如何在另一个过程中调用oracle过程和函数

时间:2019-09-24 16:14:52

标签: oracle function stored-procedures plsql

我遇到一种情况,需要执行以下操作。

第一步:使用给定的输入值调用一个过程,并获得2个输出值。

step2:使用输入参数以及Step1(过程调用)的输出值之一来调用函数

Step3:从Step2的返回值中提取输出值。

请帮助,如何处理这种情况。

谢谢

1 个答案:

答案 0 :(得分:1)

一个非常基本的示例,由变量名,数据类型(为简化起见,所有数字)以及过程/函数名和签名组成:

create or replace procedure wrapper_proc as
  -- define local variables; use appropriate data types!
  l_input_1 number;
  l_input_2 number;
  l_output_1 number;
  l_output_2 number;
  l_result number;
begin
  -- Step1: Call a procedure with the given input values and get the 2 output values.
  l_input_1 := 42;
  l_input_2 := 128;
  your_proc (l_input_1, l_input_2, l_output_1, l_output_2);
  -- l_output_1 and l_output_2 are not set by that first procedire

  -- step2: Call the function with input parameters along with one of the output value from Step1(procedure call)
  -- assuming same two original inuts, and one of the procedure outputs...
  l_result := your_func (l_input_1, l_input_2, l_output_2);

  --Step3: Extract the output value from the return value of Step2.
  -- do something unspecified with l_result
  dbms_output.put_line('Final result was: ' || l_result);
end;
/

或者如果您要将输入值传递到该包装程序中,则:

create or replace procedure wrapper_proc (
  -- arguments; use appropriate data types!
  p_input_1 number,
  p_input_2 number
) as
  -- define local variables; use appropriate data types!
  l_output_1 number;
  l_output_2 number;
  l_result number;
begin
  -- Step1: Call a procedure with the given input values and get the 2 output values.
  your_proc (p_input_1, p_input_2, l_output_1, l_output_2);
  -- l_output_1 and l_output_2 are not set by that first procedire

  -- step2: Call the function with input parameters along with one of the output value from Step1(procedure call)
  -- assuming same two original inuts, and one of the procedure outputs...
  l_result := your_func (p_input_1, p_input_2, l_output_2);

  --Step3: Extract the output value from the return value of Step2.
  -- do something unspecified with l_result
  dbms_output.put_line('Final result was: ' || l_result);
end;
/