Was this helpful?
Cursor Declaration
Before using a cursor in an application, the cursor 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 be used to retrieve data. A cursor is always associated with a SELECT statement. The select is executed when the cursor is opened. Updates can be performed only if the cursor SELECT statement refers to a single table (or updatable view) and does not include any of the following elements:
Aggregate functions
DISTINCT
GROUP By clause
HAVING clause
ORDER BY clause
UNION clause
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. The cursor name cannot exceed 32 bytes and can be assigned dynamically. For details, see Summary of Cursor Positioning.
Last modified date: 04/03/2024