NonStop SQL/MP Reference Manual

Table Of Contents
NonStop SQL/MP Reference Manual142115
C-164
Examples—CURRENT_TIMESTAMP
In contrast, the following statements also execute the same statement S twice, but
use the same Julian timestamp (the time SET PARAM executed) for each execution:
SET PARAM ?T CURRENT_TIMESTAMP; EXECUTE S; EXECUTE S:
Examples—CURRENT_TIMESTAMP
To print the current date in a detail line, include the following items in the print list:
"Date: ", CURRENT_TIMESTAMP AS DATE "D2/M2/Y2", SPACE 5,
"Time: ", CURRENT_TIMESTAMP AS TIME "HP2:M2"
For example, on March 15, 1994 at 1:30 p.m., the detail line prints:
Date: 03/15/94 Time: 01:30 PM
Cursors
A cursor is a named mechanism defined by a SELECT statement and used in a host
language program. An opened cursor can be thought of as scanning the set of records
specified by the SELECT operation. The program processes a cursor like a sequential
file, fetching rows one by one. The row being fetched is at the current position of the
cursor. The program can use the current cursor position to designate a row to delete or
update. A cursor name is an SQL identifier.
Operations for each cursor used must execute in the following order:
1. DECLARE defines the cursor.
2. OPEN determines the result table to fill the cursor and, for audited tables or views,
associates the cursor with a TMF transaction. The program must set values of host
variables or parameters in the cursor definition before the OPEN.
3. FETCH fills the cursor on the first fetch and then locks rows according to the access
specified on the SELECT statement associated with the cursor. If a sort is required,
all rows in the result table might be retrieved at this time and placed in a temporary,
sorted table.
4. DELETE or UPDATE WHERE CURRENT deletes or updates the row at the current
position of the cursor.
5. CLOSE (or FREE RESOURCES) releases the result table established on the OPEN.
A loop can execute multiple sequences of operations 3 and 4. Operation 5 can be
performed any time after operation 2.
If the cursor locks or updates an audited table, the FETCH operation and subsequent
cursor operations must be within a TMF transaction.
A process that uses a cursor must have read authority for tables and protection views
referred to in the SELECT associated with the cursor. If the cursor refers to a shorthand
view, the process must have read authority for tables or protection views underlying the
shorthand view. If the cursor declaration specifies FOR UPDATE, the process must also