Reputation: 105
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.
Upvotes: 6
Views: 26515
Reputation: 15184
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.
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.
--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 $1;
$$
LANGUAGE 'sql' VOLATILE;
--example
SELECT * FROM fn_sqltestmulti('%stuff%');
--OUTPUT--
test_id | test_stuff
---------+--------------------
1 | this is more stuff
2 | this is new stuff
Upvotes: 7