DECLARE Statement

Defines a cursor. Once declared, row sets for cursors are assigned by using the OPEN statement. (The DECLARE statement can also be used to define the name and type of local variables for a batch or procedure. For more information on variable declaration and assignment, see the DECLARE Statement.)

Syntax

DECLARE cursor_name [INSENSITIVE] [SCROLL] CURSOR
FOR select_statement
[FOR {READ ONLY | UPDATE [OF column_list]}]

where

cursor_name
Is the name of the cursor being defined. The cursor_name must conform to the rules for identifiers.
INSENSITIVE
Defines a cursor that makes a temporary copy of the data to be used by the cursor. All requests to the cursor are answered from this temporary table; therefore, modifications made to base tables will not be reflected in the data returned by fetches made to this cursor, and this cursor does not allow modifications.
SCROLL
Specifies that all methods of fetching data are available. Committed deletes and updates made to the underlying tables (by any users) are reflected in subsequent fetches (provided that the cursor is not declared with the INSENSITIVE option).
select_statement
Is a standard SELECT statement used to identify a set of rows from a given table or tables within a database. If each of the underlying tables does not have a unique index, the cursor will automatically be an INSENSITIVE cursor.

The keywords COMPUTE, COMPUTE BY, FOR BROWSE, and INTO are not allowed within the select_statement of a cursor declaration.

If DISTINCT, UNION, GROUP BY, and/or HAVING are used, one or more of the underlying tables does not have a unique index, an outer join is used, or a constant expression is included in the select_list, the cursor will be created as INSENSITIVE.

READ ONLY
Prevents updates from occurring against any row within this cursor. This option overrides the default capability of a cursor to be updated.
UPDATE [OF column_list]
Defines updatable columns within the cursor. If OF column_list is supplied, only the columns listed will allow modifications. If no list is supplied, all columns can be updated unless the cursor has been defined as READ ONLY.