Previous Topic: Using PREPARENext Topic: Executing Prepared SELECT Statements


Using EXECUTE

Why You Use EXECUTE

You use EXECUTE to execute a dynamically compiled (prepared) statement other than SELECT. This is the format of the EXECUTE statement:

EXEC SQL
  EXECUTE statement-name
END-EXEC.

The parameter statement-name must correspond to the value in the same parameter of a PREPARE statement that has already been issued in the same transaction.

EXECUTE Example

In this example, the statement prepared in an earlier example is executed:

EXEC SQL
  EXECUTE DYNAMIC_STATEMENT
END-EXEC.

Error-checking

There is no error-checking technique that is specific to EXECUTE. Check for SQLCODE < 0, or check for a specific SQLSTATE value if appropriate.

Repeating EXECUTE

You can repeat an EXECUTE statement in the same transaction because CA IDMS retains all dynamically compiled statements for the duration of the transaction.

If the program prepares more than one statement in a database transaction using the same statement name, an EXECUTE issued for the statement name will execute the most recently prepared statement.