14.9 CREATE PACKAGE Statement
PACKAGE statement creates or replaces the specification for a stored package, which is an encapsulated collection of related procedures, functions, and other program objects stored as a unit in the database.
The package specification declares these objects. The package body, specified subsequently, defines these objects.
To create or replace a package in your schema, you must have the
PROCEDURE system privilege. To create or replace a package in another user's schema, you must have the
PROCEDURE system privilege.
To embed a
PACKAGE statement inside an Oracle database precompiler program, you must terminate the statement with the keyword
END-EXEC followed by the embedded SQL statement terminator for the specific language.
( sharing_clause ::= , default_collation_clause ::= , invoker_rights_clause ::= , accessible_by_clause ::= , item_list_1 ::= )
( cursor_declaration ::= , item_declaration ::= , type_definition ::= )
Re-creates the package if it exists, and recompiles it.
Users who were granted privileges on the package before it was redefined can still access the package without being regranted the privileges.
If any function-based indexes depend on the package, then the database marks the indexes
[ EDITIONABLE | NONEDITIONABLE ]
Specifies whether the package is an editioned or noneditioned object if editioning is enabled for the schema object type
EDITIONABLE. For information about editioned and noneditioned objects, see Oracle Database Development Guide.
Name of the schema containing the package. Default: your schema.
A package stored in the database. For naming conventions, see "Identifiers".
Defines every type in the package and declares every cursor and subprogram in the package. Every declaration must have a corresponding definition in the package body. The headings of corresponding declarations and definitions must match word for word, except for white space.
Restriction on item_list_1
AUTONOMOUS_TRANSACTION cannot appear here.
Example 14-19 Creating the Specification for the emp_mgmt Package
This statement creates the specification of the
CREATE OR REPLACE PACKAGE emp_mgmt AS FUNCTION hire (last_name VARCHAR2, job_id VARCHAR2, manager_id NUMBER, salary NUMBER, commission_pct NUMBER, department_id NUMBER) RETURN NUMBER; FUNCTION create_dept(department_id NUMBER, location_id NUMBER) RETURN NUMBER; PROCEDURE remove_emp(employee_id NUMBER); PROCEDURE remove_dept(department_id NUMBER); PROCEDURE increase_sal(employee_id NUMBER, salary_incr NUMBER); PROCEDURE increase_comm(employee_id NUMBER, comm_incr NUMBER); no_comm EXCEPTION; no_sal EXCEPTION; END emp_mgmt;
The specification for the
emp_mgmt package declares these public program objects:
All of these objects are available to users who have access to the package. After creating the package, you can develop applications that invoke any of these public procedures or functions or raise any of the public exceptions of the package.
Before you can invoke this package's procedures and functions, you must define these procedures and functions in the package body. For an example of a
BODY statement that creates the body of the
emp_mgmt package, see "CREATE PACKAGE BODY Statement".
In this chapter:
In other chapters: