Dynamic commands

Dynamic commands are available only with Open Client CT-Library System 10 or later. This section describes how the DB2 access service processes dynamic commands through DB2 UDB.

Dynamic commands allow an application to execute SQL statements (such as insert, update, and delete) that contain variables with values that are determined at runtime, in the following manner:

  1. An application prepares a dynamic SQL statement by associating a SQL statement that contains placeholders with an identifier.

  2. The statement goes through SQL transformation, where it is precompiled. The results depend on the SQL transformation mode.

  3. The statement is stored in the DB2 access service, where it waits for values to replace the placeholders. The statement is then called a “prepared statement.”

  4. After the placeholders are replaced by values, the DB2 access service sends the statement to the target for execution.

This is an example of a dynamic SQL command:

insert into table2 (col1, col2) values (SALES1, SALES2)

This is the same command using parameter markers:

insert into table2 (col1, col2) values (?, ?)

The DB2 access service prepares the preceding statement. The statement executes and substitutes the values “SALES1” and “SALES2” into the parameter markers.

You can prepare and execute dynamic SQL statements by mapping these commands to DB2 capabilities, for example:

For more information about how to prepare and execute statements with dynamic SQL, see the Open Client Client-Library/C Reference Manual and the IBM DB2 SQL Reference Manual.