CREATE PACKAGE BODY statement (PL/SQL)

The CREATE PACKAGE BODY statement creates a package body, which contains the implementation of all of the procedures and functions that are declared within the package specification, as well as any declaration of private types, variables, and cursors.

Syntax

Read syntax diagramSkip visual syntax diagramCREATEOR REPLACE PACKAGE BODYpackage-nameISASprivate-declarationprocedure-specificationfunction-specificationBEGINinitialization-statementEND
procedure-specification
Read syntax diagramSkip visual syntax diagramPROCEDUREprocedure-name(,parameter)ISASprocedure-declarationBEGINstatementEXCEPTIONWHENconditionORTHENhandler-statementEND
function-specification
Read syntax diagramSkip visual syntax diagramFUNCTIONfunction-name(,parameter)RETURNreturn-typeISASfunction-declarationBEGINstatementEXCEPTIONWHENconditionORTHENhandler-statementEND

Description

package-name
Specifies the name of the package whose body is to be created. A package specification with the same name must exist.
private-declaration
Specifies the name of a private object that can be accessed by any procedure or function within the package. There can be zero or more private variables. The private-declaration can be any of the following:
  • Variable declaration
  • Record declaration
  • Collection declaration
  • REF CURSOR and cursor variable declaration
  • TYPE definitions for records, collections, or variables of the REF CURSOR type
  • SUBTYPE definition over a base type
procedure-name
Specifies the name of a public procedure that is declared in the package specification and its signature. The signature can specify any one of the following: the formal parameter names, data types, parameter modes, the order of the formal parameters, or the number of formal parameters. When the procedure name and package specification exactly match the signature of the public procedure's declaration, procedure-name defines the body of this public procedure.

If none of these conditions is true, procedure-name defines a new private procedure.

parameter
Specifies a formal parameter of the procedure.
procedure-declaration
Specifies a declaration that can be accessed only from within procedure procedure-name. This is a PL/SQL statement.
statement
Specifies a PL/SQL program statement.
function-name
Specifies the name of a public function that is declared in the package specification and its signature. The signature can specify any one of the following: the formal parameter names, data types, parameter modes, the order of the formal parameters, or the number of formal parameters. When the function name and package specification exactly match the signature of the public function's declaration, function-name defines the body of this public function.

If none of these conditions is true, function-name defines a new private function.

parameter
Specifies a formal parameter of the function.
return-type
Specifies the data type of the value that is returned by the function.
function-declaration
Specifies a declaration that can be accessed only from within function function-name. This is a PL/SQL statement.
statement
Specifies a PL/SQL program statement.
initialization-statement
Specifies a statement in the initialization section of the package body. The initialization section, if specified, must contain at least one statement. The statements in the initialization section are executed once per user session when the package is first referenced.

Notes

The CREATE PACKAGE BODY statement can be submitted in obfuscated form. In an obfuscated statement, only the package name is readable. The rest of the statement is encoded in such a way that it is not readable, but can be decoded by the database server. Obfuscated statements can be produced by calling the DBMS_DDL.WRAP function.