Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between IN, OUT, IN OUT parameters in PLSQL

Tags:

oracle

plsql

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.

like image 481
Weli Nuwan Avatar asked Jul 24 '12 03:07

Weli Nuwan


People also ask

What is in and out parameters in PL SQL?

An IN OUT parameter passes an initial value to a subprogram and returns an updated value to the caller. It can be assigned a value and the value can be read. The actual parameter corresponding to an IN OUT formal parameter must be a variable, not a constant or an expression. Formal parameter must be assigned a value.

What are the 3 modes of parameters?

PL/SQL procedure parameters can have one of three possible modes: IN, OUT, or IN OUT.

What is the difference between parameter and output parameter in stored procedure?

Input parameters allow the caller to pass a data value to the stored procedure or function. Output parameters allow the stored procedure to pass a data value or a cursor variable back to the caller. User-defined functions cannot specify output parameters.

What is in and in out in procedure in Oracle?

An input/output parameter is a parameter that functions as an IN or an OUT parameter or both. The value of the IN/OUT parameter is passed into the stored procedure/function and a new value can be assigned to the parameter and passed out of the module. An IN/OUT parameter must be a variable, not a constant.


1 Answers

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.

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 OUTPUT parameters - return multiple records

--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

MORE EXAMPLES

like image 129
waldyr.ar Avatar answered Sep 30 '22 17:09

waldyr.ar