SQL/MP Programming Manual for C

Data Retrieval and Modification
HP NonStop SQL/MP Programming Manual for C429847-008
4-18
DECLARE CURSOR Statement
Do not open multiple cursors on a table if any of the cursors are used to update
that table.
DECLARE CURSOR Statement
The DECLARE CURSOR statement names and defines a cursor and associates the
cursor with a SELECT statement that specifies the rows to retrieve.
A C program requires no special authorization to run a DECLARE CURSOR
statement.
Follow these guidelines when you use a DECLARE CURSOR statement:
The cursor name specified in the DECLARE CURSOR statement is an SQL
identifier and is not case-sensitive. For example, NonStop SQL/MP considers Cur,
cur, CUR, and CuR as equivalent names.
Declare all host variables you use in the associated SELECT statement before the
DECLARE CURSOR statement. Host variables must also be within the same
scope as all the SQL statements that refer to them.
Place the DECLARE CURSOR statement in listing order before other SQL
statements, including the OPEN, FETCH, INSERT, DELETE, UPDATE, and
CLOSE statements, that refer to the cursor. The DECLARE CURSOR statement
must also be within the scope of statements that reference the cursor.
The DECLARE CURSOR statement does not affect the values in the SQLCA and
SQLSA data structures.
This example declares a cursor list_by_partnum:
EXEC SQL BEGIN DECLARE SECTION;
struct parts_type /* host variables */
{
short partnum;
char partdesc[19];
long price;
short qty_available
} parts_rec;
EXEC SQL END DECLARE SECTION;
...
EXEC SQL DECLARE list_by_partnum CURSOR FOR
SELECT partnum,
partdesc,
price,
qty_available
FROM =parts
WHERE partnum >= :parts_rec.partnum
ORDER BY partnum
BROWSE ACCESS;
...