background image
<< Creating and Using Packages | Creating a Package >>
<< Creating and Using Packages | Creating a Package >>

Guidelines for Packages

Creating and Using Packages
4-10 Oracle Database 2 Day Developer's Guide
referenced from outside of the package. The specification is the interface to the
package. Applications that call the subprograms in a package only need to know the
names and parameters from the package specification.
The standard package specification has this form:
CREATE OR REPLACE PACKAGE
package_name
AS
type definitions for records, index-by tables
constants
exceptions
global variable declarations
procedure
procedure_1
(
arg1
, ...);
...
function
function_1
(
arg1
,...) return
datat_ype
;
...
END
package_name
;
The package body contains the code that implements these subprograms, the code for
all private subprograms that can only be invoked from within the package, and the
queries for the cursors. You can change the implementation details inside the package
body without invalidating the calling applications.
The package body has this form:
CREATE OR REPLACE PACKAGE BODY
package_name
AS
PROCEDURE
procedure_1
(
arg1
,...) IS
BEGIN
...
EXCEPTION
...
END
procedure_1
;
...
FUNCTION
function_1
(
arg1
,...) RETURN
data_type
IS
result_variable
data_type
BEGIN
...
RETURN
result_variable
;
EXCEPTION
...
END
function_1
;
...
END
package_name
;
Guidelines for Packages
You should become familiar with the packages supplied with Oracle Database and
avoid writing code that duplicates existing features.
You should design and define the package specification before writing the
implementation in the package body. In the specification, include only those parts that
must be publicly visible to calling programs, and hide private declarations within the
package body. This prevents unsafe dependencies of other programs on your
implementation details.
Because PL/SQL has a single-pass compiler, you may find that the dependencies
between correct and valid subprograms within the package body prevent you from
See Also:
Oracle Database PL/SQL Language Reference for more information
on the syntax for creating a package