A program package, known as a package for short, consists of Procedural Language (PL) components such as stored procedures, functions, variables, constants, and cursors.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
It encapsulates these PL components in a way that has the characteristics of an object-oriented programming language. A package is roughly equivalent to a C++ or Java class in which a variable of the package can be compared to a member variable of the class, and a stored procedure and a function can be compared to a class method. Categorizing related modules as a package enables programmers to develop stored procedures by using object-oriented methods in a way that is easy to manage and understand.
Like in a class, program components in a package are also grouped into public and private components that allow different scopes of access. A public component can be accessed not only by functions and stored procedures in the package, but also by PL programs outside the package. A private component, on the contrary, can be accessed only by functions and programs in the package.
You can use packages to manage stored subprograms for the following advantages:
Packages hide implementation details from applications. Hiding implementation details from the client is a widely accepted best practice, and many users allow applications to read and write the database only through subprogram interfaces provided by the package. Some users may allow using a
SELECTstatement to read the database, but modifications to the database can be made only through subprograms in the package. Therefore, you can encapsulate the business process logic in a subprogram in the package, which is easy to modify.When a subprogram in a package is called, the name of the package must be referenced. This eliminates the possibility of code errors due to the conflict between the keyword of the database versions and the name of the subprogram.