The CREATE 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 together 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 own schema, you must have the CREATE PROCEDURE system privilege. To create or replace a package in another user's schema, you must have the CREATE ANY PROCEDURE system privilege.

To embed a CREATE PACKAGE statement inside an the database precompiler program, you must terminate the statement with the keyword END-EXEC followed by the embedded SQL statement terminator for the specific language.


create_package ::=

Description of the illustration create_package.gif

(invoker_rights_clause ::=, item_list_1 ::=)

invoker_rights_clause ::=

Description of the illustration invoker_rights_clause.gif

Keyword and Parameter Descriptions


Specify OR REPLACE to re-create the package specification if it already exists. Use this clause to change the specification of an existing package without dropping, re-creating, and regranting object privileges previously granted on the package. If you change a package specification, then the database recompiles it.

Users who had previously been granted privileges on a redefined package 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 DISABLED.


Specify the schema to contain the package. If you omit schema, then the database creates the package in your own schema.


Declares package elements. If an item in item_list_1 is a pragma, it must one of the following:


A package stored in the database. For naming conventions, see Identifiers.


Specifies the AUTHID property of the member functions and procedures of the object type. For information about the AUTHID property, see "Using Invoker's Rights or Definer's Rights (AUTHID Clause)".


Specify CURRENT_USER to indicate that the package executes with the privileges of CURRENT_USER. This clause creates an invoker's rights package.

This clause also specifies that external names in queries, DML operations, and dynamic SQL statements resolve in the schema of CURRENT_USER. External names in all other statements resolve in the schema in which the package resides.


Specify DEFINER to indicate that the package executes with the privileges of the owner of the schema in which the package resides and that external names resolve in the schema where the package resides. This is the default and creates a definer's rights package.

See Also:

Using Invoker's Rights or Definer's Rights (AUTHID Clause) for more information about invoker's rights and definer's rights


Declares a list of items. For syntax, see Block.

If an item in item_list_1 is a pragma, it must one of the following:


Creating a Package: Example The following statement creates the specification of the emp_mgmt package.

   FUNCTION hire (last_name VARCHAR2, job_id VARCHAR2, 
      manager_id NUMBER, salary NUMBER, 
      commission_pct NUMBER, department_id NUMBER) 
   FUNCTION create_dept(department_id NUMBER, location_id 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 the following public program objects:

  • The functions hire and create_dept

  • The procedures remove_emp, remove_dept, increase_sal, and increase_comm

  • The exceptions no_comm and no_sal

All of these objects are available to users who have access to the package. After creating the package, you can develop applications that call any of these public procedures or functions or raise any of the public exceptions of the package.

Before you can call this package's procedures and functions, you must define these procedures and functions in the package body. For an example of a CREATE PACKAGE BODY statement that creates the body of the emp_mgmt package, see CREATE PACKAGE BODY Statement.

Related Topics