Fujitsu J2X0-1634-01EN Computer Accessories User Manual


 
declaration specifies the tables in which data is to be manipulated and the method by which data is to be fetched.
Before data can be manipulated using a cursor, the cursor must be declared. The cursor declaration must be coded
before any SQL statements that use the cursor are coded, regardless of the execution sequence of the application
program.
Data is manipulated in the following sequence using a cursor:
1. The OPEN statement opens the cursor.
2. The FETCH statement positions the cursor at a specific row in the table and fetches data.
3. The data in the row where the cursor is positioned is processed.
- Use an application program to process fetched data.
- Use the UPDATE statement to update values in the row where the cursor is positioned.
- Use the DELETE statement to delete the row where the cursor is positioned.
4. The CLOSE statement closes the cursor.
To process more than one row, repeat steps 2) and 3). These steps are illustrated in the flowchart in Figure: Flowchart
of using cursor to manipulation data.
[Figure: Flowchart of using cursor to manipulation data]
Figure: Example of an application program that uses a cursor to manipulate data is an example of an application
program that uses a cursor to manipulate data. The application program processes the STOCK table as follows:
· Deletes rows in which STOCKQTY is "0"
· Changes WHCODE to "5" in rows for which PRODUCT is REFRIGERATOR.
42