Was this helpful?
Cursor Declaration
Before a cursor can be used in an application, it must be declared. The syntax for declaring a cursor is:
EXEC SQL DECLARE cursor_name CURSOR FOR
select_statement;
The DECLARE CURSOR statement assigns a name to the cursor and associates the cursor with a SELECT statement to use to retrieve data. A cursor is always associated with a particular SELECT statement. The select is executed when the cursor is opened.
Updates can be performed only if the cursor's SELECT statement does not include any of the following elements:
Aggregates
Union clause
Group by clause
Having clause
Distinct
These elements can be present in subselects within the SELECT statement, but must not occur in the outermost SELECT statement.
The cursor_name can be specified using a string literal or a host language string variable. Cursor names can be assigned dynamically. For details, see Example of Dynamically Specified Cursor Names.
Last modified date: 08/28/2024