Subject Explicit Cursors
Author Geoff Worboys
Hi All,

I've trying to find out what I can about explicit cursors.
(I've gone for years without ever using explicit cursors,
so please bear with me.) What remains unclear to me is
whether they are mostly a syntactic convenience or whether
they have more explicit advantages.

That is not to knock syntactic convenience, our PSQL code
could benefit from more of it, but I am looking to try and
work out whether I should be consciously trying to use
cursors more often, or whether it's just a matter of what
produces the clearest looking code.

Take the example from the release notes:

DECLARE RNAME CHAR(31);
DECLARE FNAME CHAR(31);
DECLARE C CURSOR FOR ( SELECT RDB$FIELD_NAME
FROM RDB$RELATION_FIELDS
WHERE RDB$RELATION_NAME = :RNAME
ORDER BY RDB$FIELD_POSITION );
BEGIN
FOR
SELECT RDB$RELATION_NAME
FROM RDB$RELATIONS
INTO :RNAME
DO
BEGIN
OPEN C;
FETCH C INTO :FNAME;
CLOSE C;
SUSPEND;
END
END


As I understand it this code could equally well have been
written using two cursors (replace the FOR SELECT with a
separate cursor) or no cursors (replace C with simply:
FOR SELECT ... ROWS 1).

The given example is very neat and reads nicely as it is,
but is there any other reason why it is better or worse
than using two cursors or none?

--
Geoff Worboys
Telesis Computing