NonStop SQL/MP Reference Manual

Table Of Contents
NonStop SQL/MP Reference Manual142115
D-24
Examples—DECLARE CURSOR
Examples—DECLARE CURSOR
The following static SQL statement defines a cursor for a read:
EXEC SQL DECLARE CURSOR1 CURSOR FOR
SELECT COL1, COL2, COL3, COL4 FROM =PARTS
WHERE COL2 >= :HOSTVAR2 ORDER BY COL2 BROWSE ACCESS;
The following static SQL statement defines a cursor for an update. The FOR
UPDATE clause lists the columns to be updated.
EXEC SQL DECLARE CURSOR1 CURSOR FOR
SELECT COL1, COL2, COL3, COL4 FROM =PARTS
WHERE (COL2 = :HOSTVAR2) STABLE ACCESS
FOR UPDATE OF COL2, COL3, COL4;
The following dynamic SQL example defines a cursor for a SELECT stored in a C
host variable. (The SELECT is not shown.)
Variable declarations:
EXEC SQL BEGIN DECLARE SECTION;
intext char[50];
...
EXEC SQL END DECLARE SECTION;
Executable code:
EXEC SQL PREPARE SELECTIT FROM :intext;
...
EXEC SQL DECLARE GETPARTS CURSOR FOR SELECTIT;
DEFAULT Clause
The DEFAULT clause specifies a default value for a column (a value to use as the value
of the column when a row is inserted without one). You can specify a default value for
any column you define with CREATE TABLE or ALTER TABLE.
The default is NULL.
{ literal }
DEFAULT { CURRENT }
{ SYSTEM }
{ NULL }