oracle PLSQL中IN、OUT、IN OUT参数的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11623653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between IN, OUT, IN OUT parameters in PLSQL
提问by Weli Nuwan
Please tell me what are the differences between IN,OUT,IN OUT parameters in PL/SQL. And also how can i return more than one values using PL/SQL Procedure.
请告诉我 PL/SQL 中的 IN、OUT、IN OUT 参数之间有什么区别。以及如何使用 PL/SQL 过程返回多个值。
回答by waldyr.ar
What are IN/OUT/INOUT parameters?
什么是输入/输出/输入参数?
These are parameters you define as part of the function argument list that get returned back as part of the result. When you create functions, the arguments are defaulted to IN parameters when not explicitly specified (which means they are passed in and not returned) which is why you sometimes see PgAdmin do something like IN somevariable variabletype when you use the function wizard.
这些是您定义为函数参数列表的一部分的参数,它们作为结果的一部分返回。当您创建函数时,参数在未明确指定时默认为 IN 参数(这意味着它们被传入而不是返回),这就是为什么当您使用函数向导时,有时会看到 PgAdmin 执行类似于 IN somevariable variabletype 的操作。
You can have INOUT parameters as well which are function inputs that both get passed in, can be modified by the function and also get returned.
您也可以拥有 INOUT 参数,这些参数是既可以传入的函数输入,也可以由函数修改并返回。
SQL OUTPUT parameters - return multiple records
SQL OUTPUT 参数 - 返回多条记录
--SQL returning multiple records
CREATE OR REPLACE FUNCTION fn_sqltestmulti(param_subject varchar,
OUT test_id integer, OUT test_stuff text) RETURNS SETOF record
AS $$
SELECT test_id, test_stuff
FROM testtable where test_stuff LIKE ;
$$
LANGUAGE 'sql' VOLATILE;
--example
SELECT * FROM fn_sqltestmulti('%stuff%');
--OUTPUT--
test_id | test_stuff
---------+--------------------
1 | this is more stuff
2 | this is new stuff