Implementing Db2 stored procedures

A stored procedure is executable code that can be called by other programs. You might choose to use stored procedures for code that is used repeatedly. Other benefits of using stored procedures include reducing network traffic, returning result sets to an application, or allowing access to data without granting the privileges to the applications.

You can create your own stored procedures to perform whatever functions you need, Db2 also provides a set of stored procedures that perform some common functions that you might find useful. These stored procedures are called Db2-supplied stored procedures.

Before you begin

You must complete some configuration tasks for the Db2 environment before you can use any of the following types of procedures:

  • External stored procedures
  • Native SQL procedures that satisfy any of the following conditions:
    • Calls at least one external stored procedure, external SQL procedure, or user-defined function.
    • Defined with ALLOW DEBUG MODE or DISALLOW DEBUG MODE.
  • External SQL procedures (deprecated)
  • Db2-supplied stored procedures

For instructions, see Installation step 21: Configure Db2 for running stored procedures and user-defined functions or Migration step 23: Configure Db2 for running stored procedures and user-defined functions (optional).

Procedure

To implement stored procedures in Db2:

  1. Create the stored procedure:
  2. Call the stored procedure in one of the following ways:

What to do next

After you complete the basic steps for implementing the stored procedure, you can complete the following tasks, as needed: