|
A FETCH statement positions an SQL cursor on a specified row of a table and retrieves values from that row by placing them into the variables in a target list.
You may choose not to use the NEXT and FROM keywords while fetching data from any cursor.
Note
Pervasive PSQL supports only the forward-only cursor. So, you will not be able to control the flow of the cursor records even by omitting NEXT FROM.
The FETCH statement in this example retrieves values from cursor c1 into the CourseName variable. The Positioned UPDATE statement in this example updates the row for Modern European History (HIS 305) in the Course table in the DEMODATA sample database:
CREATE PROCEDURE UpdateClass(); BEGINEND;DECLARE :CourseName CHAR(7); DECLARE :OldName CHAR(7); DECLARE c1 cursor FOR SELECT name FROM course WHERE name = :CourseName; OPEN c1; SET :CourseName = 'HIS 305'; FETCH NEXT FROM c1 INTO :OldName; UPDATE SET name = 'HIS 306' WHERE CURRENT OF c1;
CREATE PROCEDURE MyProc(IN :CourseName CHAR(7)) AS BEGINENDDECLARE cursor1 CURSOR FOR SELECT Degree, Residency, Cost_Per_Credit FROM Tuition ORDER BY ID; ......... ......... FETCH cursor1 INTO :CourseName; ......... .........
|
Chapter contents
Prev topic: EXISTS
|