Package specification syntax
Updated at:
A package specification defines the public interface for a package: the functions, procedures, types, exceptions, and cursors visible to package users.
Synopsis
CREATE [ OR REPLACE ] PACKAGE 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 } [, ...] ); ]
}
] ...
[ package_name ] ;Description
CREATE PACKAGE defines a new package specification. CREATE OR REPLACE PACKAGE creates a new package specification or replaces an existing one.
Each package must have a unique name within the schema.
Parameters
| Parameter | Description |
|---|---|
package_name | The identifier assigned to the package. Each package must have a unique name within the schema. |
AUTHID DEFINER | Uses the permissions of the package owner to determine access to database objects. This is the default when the AUTHID clause is omitted. |
AUTHID CURRENT_USER | Uses the permissions of the current user running a program in the package to determine access permissions. |
declaration | A public variable declaration, accessible from outside the package using package_name.variable syntax. Define all public variables before declaring procedures or functions. Valid declaration types: variable declaration, record declaration, collection declaration, REF CURSOR and cursor variable declaration, TYPE definitions for records, collections, and REF CURSORs, exception, or object variable declaration. |
proc_name | The name of a public procedure. |
func_name | The name of a public function. |
argname | The name of an argument, referenced by this name within the function or procedure body. |
IN | IN OUT | OUT | The argument mode. IN (default): the argument accepts input only. IN OUT: the argument receives a value and returns a value. OUT: the argument returns output only. |
argtype | The data type of an argument. This can be a base data type, a column type reference using %TYPE, or a user-defined type such as a nested table or an object type. Base data types cannot include a length constraint—use VARCHAR2, not VARCHAR2(10). Use tablename.columnname%TYPE to anchor the argument type to a column definition. |
DEFAULT value | A default value for an IN argument when none is provided at call time. Cannot be specified for IN OUT or OUT arguments. |
rettype | The data type returned by a function. |
DETERMINISTIC | A synonym for IMMUTABLE. A DETERMINISTIC function cannot modify the database and always returns the same result for the same argument values. This function does not query the database and does not use information that is not in the argument list. Calls with all-constant arguments can be replaced with the function's return value. |
RNDS | RNPS | TRUST | WNDS | WNPS | Keywords accepted for compatibility with Oracle PRAGMA RESTRICT_REFERENCES syntax and ignored at runtime. |
Example
The following package specification empinfo declares three public components: a variable, a 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;What's next
Is this page helpful?