ALLBASE/SQL Reference Manual (36216-90216)

Chapter 10 375
SQL Statements A - D
DECLARE CURSOR
3. Bulk fetching
In some instances, using the BULK option is more efficient than advancing the cursor a
row at a time through many rows, especially when you want to operate on the rows with
non-ALLBASE/SQL statements.
DECLARE ManyRows CURSOR FOR
SELECT *
FROM PurchDB.Inventory
OPEN ManyRows
BULK FETCH ManyRows INTO :Rows, :Start, :NumRow
4. Dynamically preprocessed SELECT
If you know in advance that the statement to be dynamically preprocessed is not a
SELECT statement, you can prepare it and execute it in one step. In other instances, it is
more appropriate to prepare and execute the statement in separate operations.
EXECUTE IMMEDIATE :Dynam1
The statement stored in :Dynam1 is dynamically preprocessed.
PREPARE Dynamic1 FROM :Dynam1
If Dynamic1 is not a SELECT statement, the SQLD field of the SQLDA data structure is
0, and you use the EXECUTE statement to execute the dynamically preprocessed
statement.
DESCRIBE Dynamic1 INTO SQLDA
EXECUTE Dynamic1
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.
After you open the cursor and place the appropriate values into the SQL Descriptor
Area (SQLDA), use the USING DESCRIPTOR clause of the FETCH statement to identify
where to place the rows selected and properly display the returned data.
DECLARE Dynamic1Cursor CURSOR FOR Dynamic1
OPEN Dynamic1Cursor
FETCH Dynamic1Cursor USING DESCRIPTOR SQLDA
.
.
.
CLOSE Dynamic1Cursor
5. Refer to the ALLBASE/SQL Advanced Application Programming Guide for a
pseudocode example of procedure cursor usage.