4 DECLARE — define a cursor
8 DECLARE cursor_name [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ] CU
9 RSOR [ { WITH | WITHOUT } HOLD ] FOR prepared_name
10 DECLARE cursor_name [ BINARY ] [ ASENSITIVE | INSENSITIVE ] [ [ NO ] SCROLL ] CU
11 RSOR [ { WITH | WITHOUT } HOLD ] FOR query
15 DECLARE declares a cursor for iterating over the result set of a
16 prepared statement. This command has slightly different semantics from
17 the direct SQL command DECLARE: Whereas the latter executes a query and
18 prepares the result set for retrieval, this embedded SQL command merely
19 declares a name as a “loop variable” for iterating over the result set
20 of a query; the actual execution happens when the cursor is opened with
26 A cursor name, case sensitive. This can be an SQL identifier or
30 The name of a prepared query, either as an SQL identifier or a
34 A SELECT or VALUES command which will provide the rows to be
35 returned by the cursor.
37 For the meaning of the cursor options, see DECLARE.
41 Examples declaring a cursor for a query:
42 EXEC SQL DECLARE C CURSOR FOR SELECT * FROM My_Table;
43 EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T;
44 EXEC SQL DECLARE cur1 CURSOR FOR SELECT version();
46 An example declaring a cursor for a prepared statement:
47 EXEC SQL PREPARE stmt1 AS SELECT version();
48 EXEC SQL DECLARE cur1 CURSOR FOR stmt1;
52 DECLARE is specified in the SQL standard.