General Summary of Dynamic SQL Processing
The following statements are used when SQL statements are dynamically submitted:
Statement
|
Description
|
ALLOCATE CURSOR
|
Allocate extended cursor. |
ALLOCATE DESCRIPTOR
|
Allocate SQL descriptor area. |
CLOSE
|
Close an open cursor. |
DEALLOCATE DESCRIPTOR
|
Deallocate SQL descriptor area. |
DEALLOCATE PREPARE
|
Deallocate prepared SQL statement. |
DECLARE CURSOR
|
Declare a cursor for a statement which will be dynamically submitted. |
DESCRIBE
|
Examine the object form of the statement and assign values to the appropriate parameters in the SQL descriptor area. |
EXECUTE
|
Execute a prepared statement (except result set generating statements). |
EXECUTE IMMEDIATE
|
Shorthand form for PREPARE followed by EXECUTE. This form can only be used for fully-defined non-result set statements with no parameter markers. |
FETCH
|
Fetch rows for a dynamic cursor. |
GET DESCRIPTOR
|
Get values from the SQL descriptor area. |
OPEN
|
Open a prepared cursor. |
PREPARE
|
Compile an SQL source statement into an internal object form. |
SET DESCRIPTOR
|
Set values in the SQL descriptor area. |
All statements submitted to dynamic SQL programs must be prepared.
All prepared statements and singleton SELECT statements, where the result-set contains only one row, are executed with the EXECUTE statement.
All other SELECT statements and calls to result set procedures are executed using OPEN and FETCH for a cursor declared with the prepared statement.
The declaration of a cursor for a statement, DECLARE CURSOR, must always precede the PREPARE operation for the same statement in an application using dynamic SQL.