Dynamic SQL
Dynamic SQL statements are prepared and executed while the program is running. Use dynamic SQL when you do not know what SQL statements your application needs to execute before run time.
Dynamic SQL prepares and executes the SQL statements within a program, while the program is running. Two types of dynamic SQL are:
- Interactive SQL
A user enters SQL statements through IMS Explorer for Development. IMS prepares and executes those statements as dynamic SQL statements.
- Embedded dynamic SQL
Your application puts the SQL source in host variables and includes PREPARE and EXECUTE statements that tell IMS to prepare and run the contents of those host variables at run time. You must precompile and bind programs that include embedded dynamic SQL.
Dynamic SQL processing
A program that provides for dynamic SQL accepts as input, or generates, an SQL statement in the form of a character string. You can simplify the programming if you know a known number of values of known types. In the most general case, in which you do not know in advance about the SQL statements that will execute, the program typically takes these steps:
- Translates the input data, including any parameter markers, into an SQL statement
- Prepares the SQL statement to execute and acquires a description of the result segment
- Obtains, for SELECT statements, enough main storage to contain retrieved data
- Executes the statement or fetches the rows of data
- Processes the information returned
- Handles SQL return codes.