Previous | Table of Contents | Next |
The most commonly defined object within a package is a procedure. Listing 6.3 shows how a procedure is defined within a package spec.
Listing 6.3 Defining a procedure within a package spec.
PACKAGE System_Errors IS TYPE MessageParts_type IS TABLE OF varchar2 (20) INDEX BY binary_integer; vLastError varchar2 (100); THIS_PACKAGE CONSTANT varchar2 (13) := 'System_Errors'; xUNHANDLED_ERROR EXCEPTION; FUNCTION Build_Message (vObjectName IN varchar2, iErrorCode IN integer, vErrorString IN varchar2); PROCEDURE Log_Error (vObjectName IN varchar2, vErrorString IN varchar2, vErrorData IN varchar2, iErrorCode IN integer); END System_Errors;
Chapter 4 provides a detailed discussion of procedures. There are only four differences between a package procedure and a standalone procedure:
System_Log.Log_Error (vObjectName => 'Conversions.Feet_To_Meters', iErrorCode => NULL_PARAMETER, vErrorString => SQLERRM, vErrorData => nFeet);
Procedures aren t created within a package spec, but the interface for a procedure is defined within the spec. Once a procedure has been defined in a package spec, the procedure must be created within the package body before the package body will compile.
Functions are also commonly defined within a package spec. Listing 6.4 shows how a function is defined within a package spec.
Listing 6.4 Defining a function within a package spec.
PACKAGE System_Errors IS TYPE MessageParts_type IS TABLE OF varchar2 (20) INDEX BY binary_integer; vLastError varchar2 (100); THIS_PACKAGE CONSTANT varchar2 (13) := 'System_Errors'; xUNHANDLED_ERROR EXCEPTION; FUNCTION Build_Message (vObjectName IN varchar2, iErrorCode IN integer, vErrorString IN varchar2); PROCEDURE Log_Error (vObjectName IN varchar2, vErrorString IN varchar2, vErrorData IN varchar2, iErrorCode IN integer); END System_Errors;
Chapter 5 provides a detailed discussion of functions. There are five important differences between standalone functions and packaged functions:
vErrorMsg := Build_Message (vObjectName => vObjectName, iErrorCode => iErrorCode, vErrorString => SQLERRM);
Like procedures, functions aren t created within a package spec, but the interface for ad the function is defined within a spec. Once a function has been defined in a package spec, the function must be created within the package body before the package body will compile.
Previous | Table of Contents | Next |