Walter wrote:

If in a stored procedure I need to extract data from a table I can use a FOR SELECT or a DECLARE VARIABLE MyVar CURSOR FOR ( .... ) statement.

Which would be the advantage of using CURSOR FOR?

In which cases it is better than a FOR SELECT?

Mark Rotteveel answers:

For one thing, declaring a cursor can be used for positioned updates and deletes (with the WHERE CURRENT OF clause), Firebird 3 will also add support for scrollable cursors, meaning you can scroll forward, backward, relative, absolute, first/last.

Walter continues:

Then, no makes sense to declare a cursor just for retrieving rows?

Where I can see an example of WHERE CURRENT OF clause?

Paul Vinkenoog anwers:

Then, no makes sense to declare a cursor just for retrieving rows?

No, for just retrieving rows FOR SELECT is easier and safer.

If you want to perform positioned updates or deletes, use FOR SELECT ... AS CURSOR.

DECLARE cursor (with the need for OPEN, FETCH, CLOSE, as well as checking row_count) is only useful if you want to walk several datasets in parallel.

See:

http://www.firebirdsql.org/file/documentation/reference_manuals/reference_material/html/langrefupd25-psql-forselect.html

http://www.firebirdsql.org/file/documentation/reference_manuals/reference_material/html/langrefupd25-psql-declare.html#langrefupd25-psql-declare-cursor

Where I can see an example of WHERE CURRENT OF clause?

http://www.firebirdsql.org/file/documentation/reference_manuals/reference_material/html/langrefupd25-psql-forselect.html#langrefupd25-psql-forselect-ascursor

Like this post? Share on: TwitterFacebookEmail


Related Articles


Author

Firebird Community

Published

Category

Gems from Firebird Support list

Tags