Apackage is a database object that groups
logically related PL/SQL types, objects, and
Packages usually have two parts, a specification
and a body, although sometimes the body is
Thespecification is the interface to your
applications; it declares the types, variables,
constants, exceptions, cursors, and subprograms
available for use.
CREATE PACKAGE name AS -- specification (visible part)
-- public type and object declarations
-- subprogram specifications
CREATE PACKAGE BODY name AS -- body (hidden part)
-- private type and object declarations
-- subprogram bodies
The body holds implementation details andprivate
declarations, which are hidden from your
you can think of the specification as an
operational interface and of the body as a "black
You can debug, enhance, or replace a package body
without changing the interface (package
specification) to the package body.
To create packages and store them permanently in
an Oracle database, you use the CREATE PACKAGE and
CREATE PACKAGE BODY statements, which you can
execute interactively from SQL*Plus or Server
In the example below, you package a record type, a
cursor, and two employment procedures. Notice that
the procedurehire_employee uses the database
sequenceempno_seq and the function SYSDATE to
insert a new employee number and hire date,
CURSOR desc_salary RETURN EmpRecTyp;
PROCEDURE hire_employee (
mgr, SYSDATE, sal, comm, deptno);
PROCEDURE fire_employee (emp_id NUMBER) IS
Packages offer several advantages: modularity, easier application design, information hiding, added functionality, and better performance.
Packages let you encapsulate logically related
types, objects, and subprograms in a named PL/SQL
Each package is easy to understand, and the
interfaces between packages are simple, clear, and
When designing an application, all you need
initially is the interface information in the
Once the specification has been compiled, stored
subprograms that reference the package can be
compiled as well.
With packages, you can specify which types,
objects, and subprograms are public (visible and
accessible) or private (hidden and inaccessible).
Now bringing you back...
Does that email address look wrong? Try again with a different email.
This action might not be possible to undo. Are you sure you want to continue?