我知道如何从Oracle中获得one返回值,如下所示
MyReturn := MY_ORACLE_SP ();如果我的_oraclesp2的返回值是,则多个。我该怎么做?
发布于 2012-02-28 14:57:50
-- 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;
/产出: 150 20
发布于 2012-02-28 15:02:20
从技术上讲,这里不是一个过程,而是一个函数 --区别在于,一个过程没有返回值,不能用作赋值语句的右侧。
你基本上有两个选择:
(1)使用外参数。在这种情况下,我将使它成为一个包含两个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;
/发布于 2012-02-28 14:54:49
使用输出参数而不是返回值。
https://stackoverflow.com/questions/9484135
复制相似问题