SQL/MP Programming Manual for COBOL
HP NonStop SQL/MP Programming Manual for COBOL—529758-003
10-1
10 Dynamic SQL Operations
Dynamic SQL is useful if you do not know all or part of an SQL statement before run 
time. In this case, you cannot program the statement into your application. The 
program must be constructed at run time. For example, you might want to process 
SQL statements from a user or accept a statement generated by an application on a 
personal computer. 
When you use dynamic SQL, you can construct or obtain SQL statements at run time 
and then compile them and execute them. A set of SQL statements known as dynamic 
SQL statements support this capability. When you use these statements, you can 
submit other SQL statements (such as UPDATE or DELETE requests) dynamically at 
run time. 
Table 10-1 summarizes dynamic SQL statements. These statements are described, 
with examples, in the remainder of this section. Your use of a specific statement 
depends on your application requirements. 
Topics include:
Using Dynamic SQL on page 10-2
Features of Dynamic SQL on page 10-5
Table 10-1. SQL Statements Used for Dynamic SQL Operations
Statement Description
DESCRIBE INPUT Obtains information about input parameters.
DESCRIBE Obtains information about output parameters (SELECT 
columns).
PREPARE Dynamically compiles a statement—such as one requested by 
a user or constructed by the program—that was not known until 
run time.
EXECUTE Executes a prepared statement.
EXECUTE IMMEDIATE Executes a statement without preparing it first.
DECLARE CURSOR Defines a cursor and associates the cursor with a statement 
name or host variable name. (Used only with SELECT 
statements.)
OPEN Opens a cursor. The dynamic form includes a USING clause 
that allows you to provide values for dynamic parameters. 
(Used only with SELECT statements.)
FETCH Fetches data through the cursor. (Used only with SELECT 
statements.)
RELEASE Deallocates space for a dynamic SQL statement prepared from 
a host variable. (Used only with SELECT statements.)
CLOSE Closes the cursor. (Used only with SELECT statements.)










