SQL Programming Manual for Pascal
NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for Pascal—528614-001
3-17
Example
The Pascal compiler dynamically generates the length for variables of type STRING.
Example
The Pascal code for an EXECUTE IMMEDIATE operation is:
{ Variable declarations: }
EXEC SQL BEGIN DECLARE SECTION;
VAR STATEMENT : STRING(300);
EXEC SQL END DECLARE SECTION;
...
PROCEDURE READ_AND_EXECUTE;
BEGIN
READLN (STATEMENT);
EXEC SQL EXECUTE IMMEDIATE :STATEMENT;
END;
FETCH
The FETCH statement positions a cursor at the next row of the result table defined by
the cursor and retrieves the column values. This statement returns each column value
from the row into the corresponding host variable.
Static SQL Cursor
A static SQL cursor can be referred to only in procedures in the compilation unit in
which the cursor was declared. This means that for static SQL programs, the
DECLARE CURSOR, OPEN, FETCH, DELETE WHERE CURRENT, UPDATE
WHERE CURRENT, and CLOSE statements that refer to the cursor must be in the
same compilation unit.
If the program exits a procedure with an open cursor, procedures that execute later can
still refer to the cursor, as long as the procedures are in the same compilation unit.
Dynamic SQL Cursor
For a dynamic SQL cursor, all statements referring to the cursor must be in the
procedure where the cursor is defined; however, if you open the cursor and use it in
one call to the procedure where it is defined, you can still use the cursor in subsequent
calls without opening the cursor again.
All Cursors
At run time, the OPEN statement must execute before all FETCH statements, and the
CLOSE statement must execute after all FETCH statements through the cursor. Any
host variable used in a DECLARE CURSOR must be in scope at every instance of an
OPEN or FETCH operation for that cursor.
For more information on cursors, see SELECT on page 3-29.