A package is a collection of PL/SQL elements such as stored procedures, functions, variables, constants, and cursors.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
A package encapsulates PL/SQL program elements and has the characteristics of object-oriented programming languages. A package is similar to a class in C++ or Java, where variables are equivalent to member variables of a class, and stored procedures and functions are equivalent to methods of a class. By grouping related modules into packages, developers can use object-oriented methods to develop stored procedures, making management and understanding easier.
Like classes, program elements in a package are divided into public and private elements. The difference between them is the scope of access. Public elements can be accessed by functions and stored procedures within the package and by PL/SQL programs outside the package. Private elements can only be accessed by functions and stored procedures within the package.
Packages can manage stored subprograms, and their main advantages are as follows:
Packages can hide the execution details from applications, which is a widely accepted best practice. Many users strictly follow this practice, allowing only applications to interact with the database through the subprogram interfaces provided by the package. Some users allow
SELECTstatements for database reads but require the use of package subprograms for modifications. This encapsulation of business logic within package subprograms makes future modifications convenient.When calling subprograms in a package, you must reference the package name. This prevents conflicts between keywords in future database versions and subprogram names, ensuring that application code does not throw errors.
