IN OUT difference : Out Parameters « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL> create or replace package PARAMETERS as
  2  FUNCTION in_out_inout(
  3  aiv_in                         in     varchar2,
  4  aov_out                           out varchar2,
  5  aiov_inout                     in out varchar2)
  6  return                                varchar2;
  7  PROCEDURE in_out_inout(
  8  aiv_in                         in     varchar2,
  9  aov_out                           out varchar2,
 10  aiov_inout                     in out varchar2);
 11  end PARAMETERS;
 12  /

Package created.

SQL>
SQL>
SQL> create or replace package body PARAMETERS as
  2  FUNCTION in_out_inout(
  3  aiv_in                         in     varchar2,
  4  aov_out                           out varchar2,
  5  aiov_inout                     in out varchar2)
  6  return                                varchar2 is
  7  begin
  8
  9    dbms_output.put_line(aiv_in);
 10    dbms_output.put_line(aov_out);
 11    dbms_output.put_line(aiov_inout);
 12    aov_out   := 'OUT';
 13    aiov_inout := aiv_in;
 14    aiov_inout := aiov_inout||'OUT';
 15
 16    dbms_output.put_line(aiv_in);
 17    dbms_output.put_line(aov_out);
 18    dbms_output.put_line(aiov_inout);
 19    return 'OK';
 20
 21  end in_out_inout;
 22
 23
 24  PROCEDURE in_out_inout(
 25  aiv_in                         in     varchar2,
 26  aov_out                           out varchar2,
 27  aiov_inout                     in out varchar2) is
 28  begin
 29
 30    dbms_output.put_line(aiv_in);
 31    dbms_output.put_line(aov_out);
 32    dbms_output.put_line(aiov_inout);
 33    aov_out   := 'OUT';
 34    aiov_inout := aiv_in;
 35    aiov_inout := aiov_inout||'OUT';
 36
 37    dbms_output.put_line(aiv_in);
 38    dbms_output.put_line(aov_out);
 39    dbms_output.put_line(aiov_inout);
 40  end in_out_inout;
 41  end PARAMETERS;
 42  /

Package body created.

SQL>
SQL>
SQL>
SQL> declare
  2      v_in                         varchar2(30) := 'IN';
  3      v_out                        varchar2(30) := 'AAA';
  4      v_inout                      varchar2(30) := 'BBB';
  5      v_return                     varchar2(30);
  6  begin
  7
  8    dbms_output.put_line('Inside test unit parameters v_in    = '||v_in);
  9    dbms_output.put_line('Inside test unit parameters v_out   = '||v_out);
 10    dbms_output.put_line('Inside test unit parameters v_inout = '||v_inout);
 11    dbms_output.put_line('Test function PARAMETERS.in_out_inout(v_in, v_out, v_inout).');
 12
 13    v_return := PARAMETERS.in_out_inout(v_in, v_out, v_inout);
 14
 15    dbms_output.put_line(v_return);
 16    dbms_output.put_line('Inside test unit parameters v_in    = '||v_in);
 17    dbms_output.put_line('Inside test unit parameters v_out   = '||v_out);
 18    dbms_output.put_line('Inside test unit parameters v_inout = '||v_inout);
 19    dbms_output.put_line('Resetting initial values...');
 20
 21    v_out   := 'AAA';
 22    v_inout := 'BBB';
 23
 24    dbms_output.put_line('Before calling the procedure...');
 25    dbms_output.put_line('Inside test unit parameters v_in    = '||v_in);
 26    dbms_output.put_line('Inside test unit parameters v_out   = '||v_out);
 27    dbms_output.put_line('Inside test unit parameters v_inout = '||v_inout);
 28    dbms_output.put_line('Test procedure PARAMETERS.in_out_inout(v_in, v_out, v_inout).');
 29
 30    PARAMETERS.in_out_inout(v_in, v_out, v_inout);
 31
 32    dbms_output.put_line('Inside test unit parameters v_in    = '||v_in);
 33    dbms_output.put_line('Inside test unit parameters v_out   = '||v_out);
 34    dbms_output.put_line('Inside test unit parameters v_inout = '||v_inout);
 35  end;
 36  /
Inside test unit parameters v_in    = IN
Inside test unit parameters v_out   = AAA
Inside test unit parameters v_inout = BBB
Test function PARAMETERS.in_out_inout(v_in, v_out, v_inout).
IN
BBB
IN
OUT
INOUT
OK
Inside test unit parameters v_in    = IN
Inside test unit parameters v_out   = OUT
Inside test unit parameters v_inout = INOUT
Resetting initial values...
Before calling the procedure...
Inside test unit parameters v_in    = IN
Inside test unit parameters v_out   = AAA
Inside test unit parameters v_inout = BBB
Test procedure PARAMETERS.in_out_inout(v_in, v_out, v_inout).
IN
BBB
IN
OUT
INOUT
Inside test unit parameters v_in    = IN
Inside test unit parameters v_out   = OUT
Inside test unit parameters v_inout = INOUT

PL/SQL procedure successfully completed.

SQL>








27.16.Out Parameters
27.16.1.OUT Parameters
27.16.2.Out parameter
27.16.3.Calling myProc
27.16.4.IN OUT difference