Progress
SQL-89
Guide and Reference


Cursor Statements

SQL cursor statements are used to define, open, and close cursors, as well as to retrieve individual rows and move the column values into procedure variables.

Table 3–3 lists the Progress/SQL cursor statements.

Table 3–3: Progress/SQL Cursor Statements  
Statement
Description
DECLARE CURSOR
Associates a cursor name with a SELECT statement.
OPEN
Selects all rows that satisfy the DECLARE CURSOR statement and positions the cursor before the first row.
FETCH
Retrieves the next row and assigns column values from that row to procedure variables. Positions the cursor on the next row or, if there is no next row, after the last row.
Positioned UPDATE
Modifies the data in the row to which the cursor is positioned.
Positioned DELETE
Deletes the row to which the cursor is positioned.
CLOSE
Closes the cursor.

The following example shows how the basic SQL cursor statements are used:

DEFINE VARIABLE namevar LIKE Customer.Name. 
DEFINE VARIABLE maxvar LIKE Customer.Credit-Limit. 
DECLARE c1 CURSOR FOR 
    SELECT Name, Credit-Limit 
    FROM Customer 
    WHERE Credit-Limit < 10000. 
OPEN c1. 
REPEAT: 
    FETCH c1 INTO namevar, maxvar. 
    UPDATE Customer 
        SET Credit-Limit = maxvar + 1000 
        WHERE CURRENT OF c1. 
END 
CLOSE c1 

Figure 3–3 defines the sequence of the cursor statements when you execute the procedure.

Figure 3–3: Cursor Execution Sequence


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095