EnterpriseDB

Previous PageTable Of ContentsNext Page

6.1.2 Package Body Syntax

The following is the syntax for the package body:

CREATE [ OR REPLACE ] PACKAGE BODY package_name
  { IS | AS }
  [ private_declaration; ] ...
  [ { PROCEDURE proc_name
      [ (parm1 [IN | IN OUT | OUT ] datatype1
      [, parm2 [IN | IN OUT | OUT ] datatype2 ] ...) ]
    { IS | AS }
    [ proc_declaration; ] ...
      BEGIN
        statement; ...
    [ EXCEPTION
        WHEN ... THEN
          statement; ...]
      END;
    |
      FUNCTION func_name
      [ (parm1 [IN | IN OUT | OUT ] datatype1
      [, parm2 [IN | IN OUT | OUT ] datatype2 ] ...) ] 
      RETURN return_type   
     {IS | AS }
     [ func_declaration; ]... 
      BEGIN
        statement; ...
    [ EXCEPTION
        WHEN ... THEN
          statement; ...]
        END; }...]
    [ BEGIN
        init_statement; ...]
END [ package_name ];

package_name is the name of the package for which this is the package body. There must be an existing package specification with the same name.

private_declaration is an identifier of a private variable that can be accessed by any procedure or function within the package. There can be none, one, or more private variables. private_declaration can be any of the following:

Variable Declaration (see Section 4.3)

Record Declaration (see Section 4.3.4)

Collection Declaration (see Section 4.9)

REF CURSOR and Cursor Variable Declaration (see Section 4.8)

TYPE Definitions for Records, Collections, and REF CURSORs

If proc_name is the same as the identifier of a public procedure declared in the package specification and the signature of proc_name (i.e., formal parameter names (parm1, parm2,...), data types (datatype1, datatype2,...), parameter modes, order of formal parameters, and number of formal parameters) exactly matches the signature of the public procedure’s declaration, then proc_name defines the body of this public procedure.

If the conditions described in the prior paragraph are not true, then proc_name defines a private procedure.

parm1, parm2,... are the formal parameters of the procedure. datatype1, datatype2,... are the data types of parm1, parm2,... respectively. IN, IN OUT, and OUT are the possible parameter modes for each formal parameter. If none are specified, the default is IN. IN parameters can also be initialized with a default value which is used in place of any IN parameter you miss.

proc_variable is an identifier of a variable that can be accessed only from within procedure, proc_name. There can be none, one, or more variables. datatype is the data type of proc_variable. statement is an SPL program statement.

If func_name is the same as the identifier of a public function declared in the package specification and the signature of func_name (i.e., formal parameter names (parm1, parm2,...), data types (datatype1, datatype2,...), parameter modes, order of formal parameters, and number of formal parameters) exactly matches the signature of the public function’s declaration, then func_name defines the body of this public function.

If the conditions described in the prior paragraph are not true, then func_name defines a private function.

parm1, parm2,... are the formal parameters of the function. datatype1, datatype2,... are the data types of parm1, parm2,... respectively. IN, IN OUT, and OUT are the possible parameter modes for each formal parameter. If none are specified, the default is IN. return_type is the data type of the value returned by the function.

func_variable is an identifier of a variable that can be accessed only from within function, func_name. There can be none, one, or more variables. datatype is the data type of func_variable. statement is an SPL program statement.

init_statement is a statement in the initialization section of the package body. The initialization section, if specified, must contain at least one statement. The statements in the initialization section are executed once per user’s session when the package is first referenced.

Previous PageTable Of ContentsNext Page

Powered by Transit