Friday 13 July 2018

PL/SQL one time only procedure

  • In PL/SQL one-time-only procedure is an anonymous block of code encapsulated within a package body,used for initializing variables and is executed only once when the package is invoked for the first time in a user session.
  • It has a BEGIN but not an END;.
  • The END; of the package body serves as the end of the one-time-only procedure within the package body.


Syntax:

/*Create package spe*/
create or replace package test as
  Function Fn_Test...; 
  Procedure Prc_Test ...;
End Test;
/

/*Create package body*/

create or replace package body TEST 
as 
 Function Fn_Test
    Begin 
      something that the function does
      return a value;
    end Fn_Test;

 Procedure Prc_Test 
   Begin
      Something that the procedure does
   end Prc_Test;

 Begin
  /*What ever you have here will be executed only once when the package is called for the first time. 
This is an anonymous block. This anonymous block with out end we call as PL/SQL one time only procedure*/
end Test;

/

No comments:

Post a Comment