>>--EXEC SQL---.------------.------DECLARE cursor_name------> +-AT db_name-+ >--.-------------.-----.---------.------.--------------.---> +-SENSITIVE---+ +-FORWARD-+ +-LOCK---------+ +-INSENSITIVE-+ +-KEYSET--+ +-LOCKCC-------+ +-DYNAMIC-+ +-OPTIMISTIC---+ +-STATIC--+ +-OPTCC--------+ +-SCROLL--+ +-OPTCCVAL-----+ +-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--------><
>>--EXEC SQL---.------------.------DECLARE cursor_name------> +-AT db_name-+ >--CURSOR FOR---result-set-generating-dml-statement--------> >------END-EXEC--------><
AT db_name | The name of a database that has been declared using DECLARE DATABASE.
Note: If you must use AT
db_name in a DECLARE CURSOR, the connection for any following statements that reference the cursor automatically switch to the connection
associated with the cursor if different than the current connection, but only for the duration of the statement.
|
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. |
result-set-generating-dml-statement | A SQL Server INSERT, non-positioned UPDATE, or DELETE statement with an OUTPUT clause. |
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.