我知道如何从Oracle中的Oracle SP 获得一个返回值,如下所示
MyReturn := MY_ORACLE_SP ();
Run Code Online (Sandbox Code Playgroud)
如果MY_ORACLE_SP2的返回值大于1.我能怎么做?
Ben*_*oit 18
-- IN arguments : you get them. You can modify them locally but caller won't see it
-- IN OUT arguments: initialized by caller, already have a value, you can modify them and the caller will see it
-- OUT arguments: they're reinitialized by the procedure, the caller will see the final value.
CREATE PROCEDURE f (p IN NUMBER, x IN OUT NUMBER, y OUT NUMBER)
IS
BEGIN
x:=x * p;
y:=4 * p;
END;
/
SET SERVEROUTPUT ON
declare
foo number := 30;
bar number := 0;
begin
f(5,foo,bar);
dbms_output.put_line(foo || ' ' || bar);
end;
/
Run Code Online (Sandbox Code Playgroud)
产出:150 20
你所拥有的在技术上不是一个过程,而是一个函数 - 不同之处在于过程没有返回值,不能用作赋值语句的右侧.
你基本上有两个选择:
(1)使用OUT参数.在这种情况下,我会使它成为一个带有两个OUT参数的过程.通常人们不喜欢也具有OUT参数的功能,因为它违反了通常的期望.@Benoit的回答显示了这种方法.
(2)定义包含多个值的类型,并将其用作函数的返回类型.例:
CREATE TYPE two_values AS object (
A NUMBER,
b number
);
/
CREATE FUNCTION get_two_values RETURN two_values AS
BEGIN
RETURN two_values(2,4);
END;
/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
71207 次 |
| 最近记录: |