Previous |
Next |
A package is a PL/SQL unit that consists of related subprograms and the explicit cursors and variables that they use.
Oracle recommends that you put your subprograms into packages. Some of the reasons are:
Packages allow you to hide implementation details from client programs.
Hiding implementation details from client programs is a widely accepted best practice. Many Oracle customers follow this practice strictly, allowing client programs to access the database only by calling PL/SQL subprograms. Some customers allow client programs to use SELECT
statements to retrieve information from database tables, but require them to call PL/SQL subprograms for all business functions that change the database.
Packaged subprograms must be qualified with package names when invoked, which ensures that their names will always work.
For example, suppose that you developed a schema-level procedure named CONTINUE
before Oracle Database 11g Release 1 (11.1). Release 11.1 introduced the CONTINUE
statement. Therefore, if you ported your code to 11.1, it would no longer compile. However, if you had developed your procedure inside a package, your code would refer to the procedure as package_name
.CONTINUE
, so the code would still compile.
Packaged subprograms can send and receive records and collections.
Standalone stored subprograms can send and receive only scalar parameters—single values with no internal components, such as VARCHAR2
, NUMBER
, and DATE
.
Note: Oracle Database supplies many PL/SQL packages to extend database functionality and provide PL/SQL access to SQL features. You can use the supplied packages when creating your applications or for ideas in creating your own stored procedures. For information about these packages, see Oracle Database PL/SQL Packages and Types Reference.
Oracle Database PL/SQL Language Reference for more reasons to use packages
Oracle Database PL/SQL Language Reference for complete information about PL/SQL packages