René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Package initializer [Oracle PL/SQL]

A package initializer is executed at most once for a session. It is executed when the package is first accessed within that session. This is demonstrated in the following:
create or replace package pck_init_ex as

  procedure print(t in varchar2);

end pck_init_ex;
/
create or replace package body pck_init_ex as

  procedure print(t in varchar2) is begin
    dbms_output.put_line(t);
  end print;

  begin -- Here's the package initalizer
    print('Loaded');

end pck_init_ex;
/
Any session:
exec pck_init_ex.print('one');
Loaded
one
exec pck_init_ex.print('two');
two
Any other session:
exec pck_init_ex.print('three');
Loaded
three
exec pck_init_ex.print('four');
four