A package is a stored sub-program that combines PL/SQL procedures and functions into a single unit. A package is an encapsulated collection of related program objects stored together in the database.
Program objects are procedures, functions, variables, constants, cursors, and exceptions.
The purpose of a package is to logically connect groups of functions and procedures together. This makes maintenance of related portions of code easier. Packages add a layer of complexity to code.
If your system contains fewer than ten procedures and functions, you are better off leaving them as separate objects rather than combining them into packages.
The package contains two main components: the package specification and the package body .
These are stored in the database as separate objects. Look at the following ToolTip to see all the components that make up a package.
The procedures and functions that are defined in the package specifications can be called from outside the package.
Each of these procedures and functions has corresponding executable blocks within the package body.
The package body can also contain private procedures and functions that are not accessible outside the package.
These are called from other procedures and functions inside the package. Private functions and procedures must never call objects
(such as procedures or other packages) that are outside the package.
The next lesson describes the pros and cons of using packages.