602SQL Documentation Index  

Cursor Declaration

cursor_declaration ::= DECLARE name [ INSENSITIVE | SENSITIVE ] [ SCROLL ] CURSOR 
    FOR cursor_specification;
cursor_specification  ::= { query_term | TABLE table_name } 
    [ FOR { READ ONLY | UPDATE [ OF column {, column }… ] ] }

A cursor is defined with this declaration. This cursor can be opened by calling the OPEN statement, and can be searched and read by calling the FETCH statement. It can be used in the UPDATE CURRENT OF and DELETE CURRENT OF statements, and can be closed with the CLOSE statement.

If the INSENSITIVE keyword is specified, data changes made to cursor are not made to the database. The cursor works with a copy of the table containing the query_term result, so the query must be evaluated as a whole when calling the OPEN statement. If the SENSITIVE keyword is specified, data changes made to the cursor are made to the database (according to the transaction isolation settings). SENSITIVE may not be specified in the definition of an uneditable cursor.

The SCROLL specification requires access to the cursor data in any order. All cursors in 602SQL have this ability, so SCROLL is ignored.

The FOR UPDATE clause allows you to edit data (incompatible with INSENSITIVE) and may only be used for editable cursors. The FOR READ ONLY clause prevents you from editing data and inserting or deleting records using this cursor regardless of sensitivity (these situations are recognized during compilation).

Variations from Intermediate to Full Level

Usage example:

DECLARE cur CURSOR FOR 
  SELECT Companies.address, CAST (SUM(Orders.ordered) AS INT) 
  FROM Companies, Orders 
  WHERE Orders.company=Companies.company 
  GROUP BY Companies.company 
FOR READ ONLY;