Difference between package and serially_reusable package

A package once executed will have its variables in UGA (User Global Area). This is by default. If you are creating a package which will be executed only once, then the memory used by the package could be freed up after its execution.

It is using a pragma (hint to compiler) that we do so. This directive is called as serially_reusable. It tells the compiler to run the package and free the space once its executed. The compiler on getting this directive does not save the program variables in UGA but it does in SGA (Shared Global Area).

Each time the package with serially_reusable directive is called, its public variables are initialized. But in a normal package its not initialized every time the package is called.

Here is an example:
create or replace package pkg_with_pragma is
pragma serially_reusable;
n number := 5; -- default initialization
end pkg_with_pragma;


set serveroutput on


BEGIN
pkg_with_pragma.N := 10;
dbms_output.put_line(pkg_with_pragma.N);
END;
/


Output is
10


BEGIN
dbms_output.put_line(pkg_with_pragma.N);
END;
/


Output is
5


create or replace package pkg_without_pragma is
n number := 5; -- default initialization
end pkg_without_pragma;
/


BEGIN
pkg_without_pragma.N := 10;
dbms_output.put_line(pkg_without_pragma.N);
END;
/


Output is
10


BEGIN
pkg_without_pragma.N := 10;
dbms_output.put_line(pkg_without_pragma.N);
END;
/


Output is
10


References: PL/SQL User's Guide and ReferenceOracle® Database Application Developer's Guide - FundamentalsBurleson Consulting