A protocol for using SQL within another language is dynamic if it enable sarbitrary SQL source code to be constructed and executed at run-time.
EXECUTE IMMEDIATE
To execute a non-parametric statement, use the command
where :string is a host variable containing the ASCII representation of the command.
Run-Time Compilation
The SQL PREPARE command is used at run-time to compile SQL commands
and to provide a handle to the generated code.
EXEC SQL PREPARE stmt FROM :string;
For SQL cursors in Embedded SQL:
EXEC SQL DECLARE cname CURSOR FOR stmt;
EXEC SQL OPEN cname
USING :var1 [,...,:vark];
EXEC SQL FETCH cname
INTO :out1 [,...,:outn];
EXEC SQL CLOSE cname;
When parameters are results are not known:
DESCRIPTOR
An SQL descriptor is used to communicate information about parameters and
results of a prepared SQL command.
SQL commands for descriptor use:
ALLOCATE DESCRIPTOR descr
GET DESCRIPTOR descr <what>
SET DESCRIPTOR descr <what>
where <what> indicates
GET/SET a value for COUNT, or
GET/SET properties for the i-th attribute: VALUE :i <prop>
where <prop> can be DATA, TYPE, INDICATOR, ...
DESCRIBE [INPUT | OUTPUT] stmt INTO descr
In practice, one uses an explicit host language sqlda data structure.
SQLDA
With normal Embedded SQL, we didn’t need to include SQLDA, only SQLCA. The sqlda data structure is an SQL description area that defines what attributes that are parameters and query answers look like, e.g., where the data is located.