Nested, Package, and Standalone Subprograms
You can create a subprogram either inside a PL/SQL block (which can be another subprogram), inside a package, or at schema level.
A subprogram created inside a PL/SQL block is a nested subprogram. You can either declare and define it at the same time, or you can declare it first and then define it later in the same block (see "Forward Declaration"). A nested subprogram is stored in the database only if it is nested in a standalone or package subprogram.
A subprogram created inside a package is a package subprogram. You declare it in the package specification and define it in the package body. It is stored in the database until you drop the package. (Packages are described in PL/SQL Packages.)
A subprogram created at schema level is a standalone subprogram. You create it with the CREATE
FUNCTION
or CREATE
PROCEDURE
statement. It is stored in the database until you drop it with the DROP
FUNCTION
or DROP
PROCEDURE
statement. (These statements are described in SQL Statements for Stored PL/SQL Units.)
A stored subprogram is either a package subprogram or a standalone subprogram. A stored subprogram is affected by the AUTHID
and ACCESSIBLE
BY
clauses, which can appear in the CREATE
FUNCTION
, CREATE
PROCEDURE
, and CREATE
PACKAGE
statements. The AUTHID
clause affects the name resolution and privilege checking of SQL statements that the subprogram issues at run time (for more information, see "Invoker's Rights and Definer's Rights (AUTHID Property)"). The ACCESSIBLE
BY
clause specifies a white list of PL/SQL units that can access the subprogram.