]> begriffs open source - ai-pg/blob - full-docs/txt/ecpg-sql-declare.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / ecpg-sql-declare.txt
1
2 DECLARE
3
4    DECLARE — define a cursor
5
6 Synopsis
7
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
12
13 Description
14
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
21    the OPEN command.
22
23 Parameters
24
25    cursor_name #
26           A cursor name, case sensitive. This can be an SQL identifier or
27           a host variable.
28
29    prepared_name #
30           The name of a prepared query, either as an SQL identifier or a
31           host variable.
32
33    query #
34           A SELECT or VALUES command which will provide the rows to be
35           returned by the cursor.
36
37    For the meaning of the cursor options, see DECLARE.
38
39 Examples
40
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();
45
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;
49
50 Compatibility
51
52    DECLARE is specified in the SQL standard.
53
54 See Also
55
56    OPEN, CLOSE, DECLARE