Creating an Oracle package is one of the most common operations when we use an Oracle database. The following describes the syntax for creating an Oracle package.
A package is a container that binds processes, functions, and data structures. A package consists of two parts: external visual package specifications, including function headers and process headers, the package body contains the declaration, execution, and exception handling of all bundled processes and functions.
The packaged PL/SQL program is very different from the one not packaged. The package data exists throughout the user's session. When the user obtains the package execution authorization, it is equivalent to obtaining permissions for all programs and data structures in the package specification. However, you cannot only authorize a function or process in the package. The package can reload processes and functions. In the package, multiple programs can be declared with the same name. during runtime, the correct program is called based on the number of parameters and data types.
To create an Oracle package, you must first create a package specification. The syntax for creating an Oracle package specification is as follows:
- CREATE [OR REPLACE] PACKAGE package_name
- {AS|IS}
- public_variable_declarations |
- public_type_declarations |
- public_exception_declarations |
- public_cursor_declarations |
- function_declarations |
- procedure_specifications
- END [package_name]
Use the create package body statement to CREATE a package body:
- CREATE [OR REPLACE] PACKAGE BODY package_name
- {AS|IS}
- private_variable_declarations |
- private_type_declarations |
- private_exception_declarations |
- private_cursor_declarations |
- function_declarations |
- procedure_specifications
- END [package_name]
Private Data structures are those inside the package body and are invisible to the called program.
Differences between Oracle procedures and functions
Example of Oracle over () function usage
Use of Oracle to_char Functions
Two cases of Java calling Oracle Functions
Implementation of oracle function return table