All Products
Search
Document Center

PolarDB:CREATE PACKAGE

Last Updated:Mar 28, 2026

Creates a package specification in PolarDB for Oracle.

Syntax

CREATE [ OR REPLACE ] PACKAGE name
[ AUTHID { DEFINER | CURRENT_USER } ]
{ IS | AS }
  [ declaration; ] [, ...]
  [ { PROCEDURE proc_name
      [ (argname [ IN | IN OUT | OUT ] argtype [ DEFAULT value ]
        [, ...]) ];
      [ PRAGMA RESTRICT_REFERENCES(name,
        { RNDS | RNPS | TRUST | WNDS | WNPS } [, ... ] ); ]
    |
      FUNCTION func_name
      [ (argname [ IN | IN OUT | OUT ] argtype [ DEFAULT value ]
        [, ...]) ]
      RETURN rettype [ DETERMINISTIC ];
      [ PRAGMA RESTRICT_REFERENCES(name,
        { RNDS | RNPS | TRUST | WNDS | WNPS } [, ... ] ); ]
    }
  ] [, ...]
  END [ name ]

Description

CREATE PACKAGE creates a package specification. CREATE OR REPLACE PACKAGE creates a new package specification or replaces an existing one.

If you specify a schema name, the package is created in that schema. Otherwise, it is created in the current schema. A new package name must be unique within its schema. To update an existing package definition, use CREATE OR REPLACE PACKAGE.

The user who creates the package is its owner.

Parameters

name

The name of the package to create. The name can be schema-qualified.

DEFINER | CURRENT_USER

Specifies whose privileges are used to determine access to database objects referenced in the package. DEFINER uses the privileges of the package owner. CURRENT_USER uses the privileges of the user executing a program in the package. The default is DEFINER.

declaration

A public variable, type, cursor, or REF CURSOR declaration.

proc_name

The name of a public stored procedure.

argname

The name of an argument.

IN | IN OUT | OUT

The argument mode.

argtype

The data type of an argument.

DEFAULT value

The default value of an input argument.

func_name

The name of a public function.

rettype

The return data type.

DETERMINISTIC

A synonym for IMMUTABLE. A DETERMINISTIC stored procedure cannot modify the database and always returns the same result for the same argument values. It does not perform database lookups or use information outside its argument list. When all arguments are constants, the call is replaced immediately with the stored procedure's return value.

RNDS | RNPS | TRUST | WNDS | WNPS

Accepted for Oracle compatibility. These keywords are ignored.

Examples

The following package specification (empinfo) declares three public components: a variable, a stored procedure, and a function.

CREATE OR REPLACE PACKAGE empinfo
IS
    emp_name        VARCHAR2(10);
    PROCEDURE get_name (
        p_empno     NUMBER
    );
    FUNCTION display_counter
    RETURN INTEGER;
END;

See also

  • CREATE PACKAGE BODY: Implement the stored procedures and functions declared in the package specification.

  • DROP PACKAGE: Remove an existing package specification and its body.