HomeOracle Page 5 - Database Interaction with PL/SQL, Named Notations, Storing Procedures and Functions
PACKAGE and PACKAGE BODY - Oracle
This is part 16 of a series of articles focusing on database interactions with Oracle PL/SQL. In my previous article, we worked with PL/SQL TABLE types in between sub-programs. In this article, we will look into Named Notation, default values of parameters, stored procedures, stored functions and finally introduce the concepts of package and package body.
A package is a single unit containing several stored sub-programs. Even a package itself gets stored inside the database (along with all of its sub-programs). Basically any package in Oracle has two parts, namely the package specification and the package body.
The package specification contains the definition or specification of all the elements in the package that may be referenced outside of the package. These are called the public elements of the package. Like the module, the package specification contains all the code that is needed for a developer to understand how to call the objects in the package. A developer should never have to examine the code behind the specification (which is the body) in order to understand how to use and benefit from the package. The package specification does not contain any executable statements or exception handlers. A specification only specifies, or declares, those objects in the package that are public -- that is, visible outside of the package and callable by other programs.
The body of the package contains all the code behind the package specification: the implementation of the modules, cursors, and other objects. The body may also contain elements that do not appear in the specification. These are called private elements of the package. A private element cannot be referenced outside of the package, since it does not appear in the specification.
The body of the package resembles a standalone module's declaration section. It contains both declarations of variables and the definitions of all package modules. The package body may also contain an execution section, which is called the initialization section because it is only run once, to initialize the package.