Packages for external stored procedures
An external stored procedure must have an associated package.
As part of the process of creating an external stored procedure, you prepare the procedure, which means that you precompile, compile, link-edit, and bind the application. The result of this process is a Db2 package. You do not need to create a Db2 plan for an external procedure. The procedure runs under the caller's thread and uses the plan from the client program that calls it.
The calling application can use a Db2 package or plan to execute the CALL statement.
Both the stored procedure package and the calling application plan or package must exist on the server before you run the calling application.
The following figure shows this relationship between a client program and a stored procedure. In the figure, the client program, which was bound into package A, issues a CALL statement to program B. Program B is an external stored procedure in a WLM address space. This external stored procedure was bound into package B.
You can control access to the stored procedure package by specifying the ENABLE bind option when you bind the package.
In the following situations, the stored procedure might use more than one package:
- You bind a DBRM several times into several versions of the same package, all of which have the same package name but reside in different package collections. Your stored procedure can switch from one version to another by using the SET CURRENT PACKAGESET statement.
- The stored procedure calls another program that contains SQL statements. This program has an associated package. This package must exist at the location where the stored procedure is defined and at the location where the SQL statements are executed.