A package is a group of procedures and functions managed as one entity.
PACKAGE
A package is a group of procedures and functions managed as one entity.
CREATE PACKAGE
Creates a package header
DSQL
CREATE PACKAGE package_name [SQL SECURITY {INVOKER | DEFINER}] AS BEGIN [ <package_item> ... ] END <package_item> ::= <function_decl>; | <procedure_decl>; <function_decl> ::= FUNCTION funcname [ ( [ <in_params> ] ) ] RETURNS <domain_or_non_array_type> [COLLATE collation] [DETERMINISTIC] <procedure_decl> ::= PROCEDURE procname [ ( [ <in_params> ] ) ] [RETURNS (<out_params>)] <in_params> ::= <inparam> [, <inparam> ... ] <inparam> ::= <param_decl> [ { = | DEFAULT } <value> ] <out_params> ::= <outparam> [, <outparam> ...] <outparam> ::= <param_decl> <value> ::= { literal | NULL | context_var } <param-decl> ::= paramname <domain_or_non_array_type> [NOT NULL] [COLLATE collation] <domain_or_non_array_type> ::= !! See Scalar Data Types Syntax !!
Parameter | Description |
---|---|
package_name |
Package name.The maximum length is 63 characters.The package name must be unique among all package names. |
function_decl |
Function declaration |
procedure_decl |
Procedure declaration |
func_name |
Function name.The maximum length is 63 characters.The function name must be unique within the package. |
proc_name |
Procedure name.The maximum length is 63 characters.The function name must be unique within the package. |
collation |
Collation |
inparam |
Input parameter declaration |
outparam |
Output parameter declaration |
literal |
A literal value that is assignment-compatible with the data type of the parameter |
context_var |
Any context variable that is assignment-compatible with the data type of the parameter |
paramname |
The name of an input parameter of a procedure or function, or an output parameter of a procedure.The maximum length is 63 characters.The name of the parameter must be unique among input and output parameters of the procedure or function. |
The CREATE PACKAGE
statement creates a new package header.Routines (procedures and functions) declared in the package header are available outside the package using the full identifier (package_name.proc_name or package_name.func_name).Routines defined only in the package body — but not in the package header — are not visible outside the package.
Note
|
Package procedure and function names may shadow global routines
If a package header or package body declares a procedure or function with the same name as a stored procedure or function in the global namespace, it is not possible to call that global procedure or function from the package body.In this case, the procedure or function of the package will always be called. For this reason, it is recommended that the names of stored procedures and functions in packages do not overlap with names of stored procedures and functions in the global namespace. |