Associates the cursor name with the specified SELECT statement and enables you to retrieve rows of data using the FETCH statement.
Syntax:
>>--EXEC SQL---.------------.------DECLARE cursor_name------>
+-AT db_name-+
>--.-------------.-----.---------.------.--------------.--->
+-SENSITIVE---+ +-FORWARD-+ +-LOCK---------+
+-INSENSITIVE-+ +-KEYSET--+ +-LOCKCC-------+
+-DYNAMIC-+ +-OPTIMISTIC---+
+-STATIC--+ +-OPTCC--------+
+-SCROLL--+ +-OPTCCVAL-----+
+-DATASET-+ +-READ ONLY----+
+-READONLY-----+
+-FASTFORWARD--+
+-FAST FORWARD-+
>--CURSOR-------.----------------.---------FOR------------->
+----WITH HOLD---+
>----.----select_stmt-----------------------.-------------->
+----stored_procedure_call_statement---+
+----prepared_stmt_name----------------+
+----OPTIMIZE FOR n ROWS---------------+
>--.-------------------------------.----------------------->
+-FOR READ ONLY-----------------+
+-FOR UPDATE-.----------------.-+
+-OF column_list-+
>------END-EXEC--------><
Parameters:
db_name
|
The name of a database that has been declared using DECLARE DATABASE.
|
cursor_name
|
Cursor name used to identify the cursor in subsequent statements. Cursor names can contain any legal filename character and be up to 30 characters in length. The first character must be a letter.
|
select_stmt
|
Any valid SQL SELECT statement, or a QUERY ODBC statement or a CALL statement for a stored procedure that returns a result set.
|
prepared_stmt_name
|
The name of a prepared SQL SELECT statement or QUERY ODBC statement.
|
stored_procedure_call_stmt
|
A valid stored procedure call which returns a result set.
|
n
|
The number of rows per block fetched when the cursor is opened. The value of
n must be less than 1000.
|
column_list
|
A list of column-names, separated by commas.
|
Example:
EXEC SQL DECLARE C1 CURSOR FOR
SELECT last_name, first_name FROM staff
END-EXEC
EXEC SQL DECLARE C2 CURSOR FOR
QUERY ODBC COLUMNS TABLENAME 'staff'
END-EXEC
Comments:
Two separately compiled programs cannot share the same cursor. All statements that reference a particular cursor must be compiled together.
The DECLARE CURSOR statement must appear before the first reference to the cursor. The SELECT statement runs when the cursor is opened. The following rules apply to the SELECT statement:
If OPTIMIZE FOR is specified, OpenESQL uses n to override the setting of the PREFETCH directive for the cursor. This allows prefetch optimization for individual cursors.
You can specify multiple SELECT statements in a DECLARE CURSOR statement, signifying the return of multiple result sets from a standard OpenESQL application program. The client application must use the GET NEXT RESULT SET statement to retrieve additional result sets.