8. SQL Statements : DECLARE CURSOR : Syntax
 
Share this page                  
Syntax
The DECLARE CURSOR statement has the following format:
EXEC SQL DECLARE cursor_name CURSOR
              FOR SELECT [ALL | DISTINCT] result_expression {, result_expression}
              FROM [schema.]table [correlation] {, [schema.]table [correlation]}
              [WHERE search_condition]
              [GROUP BY column {, column}]
              [HAVING search_condition]
              [UNION [all] full_select]
              [ORDER BY ordering-expression [ASC | DESC]
                            {, ordering-expression [ASC | DESC]}]
              [FOR [DEFERRED | DIRECT] UPDATE OF column {, column}]
Dynamic SQL form:
EXEC SQL DECLARE cursor_name CURSOR
              FOR statement_name;
cursor_name
Assigns a name to the cursor. The name can be specified using a quoted or unquoted string literal or a host language string variable. If cursor_name is a reserved word, it must be specified in quotes.
Limits: The cursor name cannot exceed 32 bytes.