ALLBASE/SQL Reference Manual (36216-90216)

Chapter 11 469
SQL Statements E - R
PREPARE
Two sections for module Statistics are stored in the system catalog.
EXECUTE Statistics(1)
The statistics for table PurchDB.Orders are updated.
EXECUTE Statistics(2)
The statistics for table PurchDB.OrderItems are updated.
DROP MODULE Statistics
Both sections of the module are deleted.
2. Programmatic use
If you know in advance that the statement to be dynamically preprocessed is not a
SELECT statement and does not contain dynamic parameters, you can prepare it and
execute it in one step, as follows:
EXECUTE IMMEDIATE :Dynam1
It may be more appropriate to prepare and execute the statement in separate
operations. For example, if you don't know the format of a statement:
PREPARE Dynamic1 FROM :Dynam1
The statement stored in :Dynam1 is dynamically preprocessed.
DESCRIBE Dynamic1 INTO Sqlda
If Dynamic1 is not a SELECT statement, the Sqld field of the Sqlda data structure is 0.
In this case, if you know there are no dynamic parameters in the prepared statement,
use the EXECUTE statement to execute the dynamically preprocessed statement.
If it is possible that dynamic parameters are present in the prepared statement, you
must describe the statement for input:
DESCRIBE INPUT Dynamic1 USING SQL DESCRIPTOR SqldaIn
If dynamic parameters are present, the appropriate data buffer or host variables must
be loaded with the values of any dynamic parameters. Then if the statement is not a
query, it can be executed, as in this example using a data buffer:
EXECUTE Dynamic1 USING SQL DESCRIPTOR SqldaIn
If Dynamic1 is a SELECT statement and the language you are using supports
dynamically defined SELECT statements, use a cursor to manipulate the rows in the
query result:
DECLARE Dynamic1Cursor CURSOR FOR Dynamic1
Place the appropriate values into the SQL descriptor areas. Use the USING
DESCRIPTOR clause of the OPEN statement to identify where dynamic parameter
information is located. Use the USING DESCRIPTOR clause of the FETCH statement to
identify where to place the rows selected.
OPEN Dynamic1Cursor USING SQL DESCRIPTOR SqldaIn