Packages and application plans

A package contains control structures that Db2 uses when it runs SQL statements. An application plan relates an application process to a local instance of Db2 and specifies processing options.

Packages are produced during program preparation. You can think of the control structures as the bound or operational form of SQL statements. All control structures in a package are derived from the SQL statements that are embedded in a single source program.

An application plan contains a list of package names.

Db2 applications require an application plan. Packages make application programs more flexible and easier to maintain.

In general, you create plans and packages by using the Db2 commands BIND PLAN and BIND PACKAGE.

Example

The following figure shows an application plan that contains two packages. Suppose that you decide to change the SELECT statement in package AA to select data from a different table. In this case, you need to bind only package AA again and not package AB.

Begin general-use programming interface information.
Figure 1. Application plan and packages
Begin figure description. Plan A contains packages AA and AB. In package AA the SQL statement changed from "SELECT * FROM TABLET" to "SELECT * FROM TABLE3". End figure description.
End general-use programming interface information.

Packages for triggers and routines

A trigger package is a special type of package that is created when you issue a CREATE TRIGGER statement. It contains the trigger body and the WHEN clause for the trigger. When the trigger activates, the package executes one or more times.

Start of changePackages are also generated, or explicitly created for certain SQL routines, including stored procedures and certain types of user defined functions. The package for a routine contains the routine body, including control statements. The package might also contain statements that are generated by Db2. Each time that the routine is invoked, the package executes one or more times.End of change

Specifically, Db2 generates a package automatically for the following types of SQL routines:

  • External scalar functions
  • External table functions
  • Compiled SQL scalar functions
  • Native SQL procedures
  • External SQL procedures

For external stored procedures, you explicitly bind the source code for the stored procedure into a package before or you issue the CREATE PROCEDURE statement. Each time that the external procedure is invoked, the package executes one or more times.

Packages for JDBC, SQLJ, and ODBC applications

Packages for JDBC, SQLJ, and ODBC applications serve different purposes. For more information, see Preparing and running JDBC and SQLJ programs and Db2 ODBC run time environment setup.