PreviousSQL Engine Reference (9.1 revision 1) Next

FETCH

Show this topic in Library frames

Remarks

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.SQL 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.

Syntax

FETCH [ [NEXT] FROM ] cursor-name INTO variable-name 

Examples

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(); 
BEGIN 
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; 
END;


CREATE PROCEDURE MyProc(IN :CourseName CHAR(7)) AS 
BEGIN 
DECLARE cursor1 CURSOR 
FOR SELECT Degree, Residency, Cost_Per_Credit 
FROM Tuition ORDER BY ID; 
......... 
......... 
FETCH cursor1 INTO :CourseName; 
......... 
......... 
END

See Also

CREATE PROCEDURE


Chapter contents
Publication contents

Prev topic: EXISTS
Next topic: FOREIGN KEY