I need explanations of OUT mode and INOUT PL/SQL and Mysql Procedure

Asked

Viewed 1,219 times

0

Well, I put PL/SQL and mysql because these two modes have in the procedures both Oracle and mysql but anyway.. The IN mode I understood that it works as a Constant, it is passed by the parameter and cannot be changed inside the Procedure.. But I am in doubt in OUT and INOUT mode, I saw that the out can be changed inside the Procedure but it does not "return" a value. What is its functionality then? and INOUT mode?

1 answer

2


In accordance with the oracle documentation the out parameters behave as an uninitialized variable, so regardless of the value you pass in the parameter, the method will receive a null value as default, allowing it to be changed, returning the value in the variable used. The In Out parameters behave as an initialized variable, the method will receive the value in the parameter and it is possible to change it too, returning the value in the variable used in the parameter. Below is a simple example of using oracle:

declare
  Letra CHAR;

  procedure AlteraOut(pLetra out char) is
  begin
    dbms_output.put_line('O valor do parâmetro out é: '||pLetra);
    pLetra := 'B';
  end;

  procedure AlteraInOut(pLetra in out char) is
  begin
    dbms_output.put_line('O valor do parâmetro in out é: '||pLetra);
    pLetra := 'C';
  end; 

begin
  Letra := 'A';

  AlteraOut(Letra);
  dbms_output.put_line('O Valor depois do procedimento out é: '||Letra);

  AlteraInOut(Letra);
  dbms_output.put_line('O Valor depois do procedimento in out é: '||Letra);  
end;

The concept in mysql is the same, according to this article

Browser other questions tagged

You are not signed in. Login or sign up in order to post.