Subject RE: [firebird-support] Examples of using cyursors within stored procedures
Author Thomas Steinmaurer
> I would like tro ask if one or more cursors can be used within stored procedures and if so if there are any examples of
> using this.

Firebird doesn't have cursors like in Oracle, but you can use a
FOR SELECT ... DO statement to iterate through a result set.

For example, a pretty simple selectable stored procedure, that
returns a result set, could look like:

SET TERM ^^ ;
CREATE PROCEDURE PRO_FACILITY_S returns (
ID Numeric(18,0),
NAME VarChar(40))
AS
BEGIN
FOR SELECT
ID,
NAME
FROM FACILITY
INTO
:ID,
:NAME
DO BEGIN
SUSPEND;
END
END
^^
SET TERM ; ^^


The FOR SELECT ... DO statement iterates over the table FACILITY
and via the SUSPEND statement, it returns the current return
parameter values to the caller. The usage of a selectable stored
procedure is the same, as when using a table.

SELECT * FROM PRO_FACILITY_S;


More examples are available in the "employee" example database,
which comes with each InterBase/Firebird installation. You also
might download the InterBase 6 Beta documentation set here:
http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_download_documentation

Or, for a full-fledged "real" Firebird documentation you might
purchase a copy of the IBPhoenix CD.



Best Regards,
Thomas Steinmaurer
LogManager Serie - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database and MS SQL Server
Upscene Productions
http://www.upscene.com