Package Components v13
Packages consist of two main components:
- The package specification: This is the public interface, (these are the elements which can be referenced outside the package). We declare all database objects that are to be a part of our package within the specification.
- The package body: This contains the actual implementation of all the database objects declared within the package specification.
The package body implements the specifications in the package specification. It contains implementation details and private declarations which are invisible to the application. You can debug, enhance or replace a package body without changing the specifications. Similarly, you can change the body without recompiling the calling programs because the implementation details are invisible to the application.
Package Specification Syntax
The package specification defines the user interface for a package (the API). The specification lists the functions, procedures, types, exceptions and cursors that are visible to a user of the package.
The syntax used to define the interface for a package is:
Where authorization_clause
:=
Where procedure_or_function_declaration
:=
Where procedure_declaration
:=
Where function_declaration
:=
Where argument_list
:=
Where argument_declaration
:=
Where restriction_pragma
:=
Where restrictions
:=
Parameters
package_name
package_name
is an identifier assigned to the package - each package must have a name unique within the schema.
AUTHID DEFINER
If you omit the AUTHID
clause or specify AUTHID DEFINER
, the privileges of the package owner are used to determine access privileges to database objects.
AUTHID CURRENT_USER
If you specify AUTHID CURRENT_USER
, the privileges of the current user executing a program in the package are used to determine access privileges.
declaration
declaration
is an identifier of a public variable. A public variable can be accessed from outside of the package using the syntax package_name.variable
. There can be zero, one, or more public variables. Public variable definitions must come before procedure or function declarations.
declaration
can be any of the following:
- Variable Declaration
- Record Declaration
- Collection Declaration
REF CURSOR
and Cursor Variable DeclarationTYPE
Definitions for Records, Collections, andREF CURSORs
- Exception
- Object Variable Declaration
proc_name
The name of a public procedure.
argname
The name of an argument. The argument is referenced by this name within the function or procedure body.
IN | IN OUT | OUT
The argument mode. IN
declares the argument for input only. This is the default. IN OUT
allows the argument to receive a value as well as return a value. OUT
specifies the argument is for output only.
argtype
The data type(s) of an argument. An argument type may be a base data type, a copy of the type of an existing column using %TYPE
, or a user-defined type such as a nested table or an object type. A length must not be specified for any base type - for example, specify VARCHAR2
, not VARCHAR2(10
).
The type of a column is referenced by writing tablename.columnname
%TYPE
; using this can sometimes help make a procedure independent from changes to the definition of a table.
DEFAULT value
The DEFAULT
clause supplies a default value for an input argument if one is not supplied in the invocation. DEFAULT
may not be specified for arguments with modes IN OUT
or OUT
.
func_name
The name of a public function.
rettype
The return data type.
DETERMINISTIC
DETERMINISTIC
is a synonym for IMMUTABLE
. A DETERMINISTIC
function cannot modify the database and always reaches the same result when given the same argument values; it does not do database lookups or otherwise use information not directly present in its argument list. If you include this clause, any call of the function with all-constant arguments can be immediately replaced with the function value.
restriction
The following keywords are accepted for compatibility and ignored:
RNDS
RNPS
TRUST
WNDS
WNPS
Package Body Syntax
Package implementation details reside in the package body; the package body may contain objects that are not visible to the package user. Advanced Server supports the following syntax for the package body:
Where procedure_or_function_definition
:=
Where procedure_definition
:=
Where procedure_body
:=
Where function_definition
:=