Firebird Documentation IndexFirebird 3.0.6 Release NotesProcedural SQL (PSQL) → PSQL Sub-routines
Firebird Home Firebird Home Prev: PSQL Stored FunctionsFirebird Documentation IndexUp: Procedural SQL (PSQL)Next: Packages

PSQL Sub-routines

Adriano dos Santos Fernandes

The header of a PSQL module (stored procedure, stored function, trigger, executable block) can now accept sub-procedure and sub-function blocks in the header declarations for use within the body of the module.

Syntax for Declaring a Sub-procedure

  DECLARE PROCEDURE <name> [(param1 [, ...])]
  [RETURNS (param1 [, ...])]
  AS
  ...
      

Syntax for declaring a Sub-function

  DECLARE FUNCTION <name> [(param1 [, ...])]
  RETURNS <type>
  AS
  ...
      

Examples

SET TERM ^;
--
-- Sub-function in EXECUTE BLOCK
--
EXECUTE BLOCK RETURNS (N INT)
AS
  DECLARE FUNCTION F(X INT) RETURNS INT
  AS
  BEGIN
    RETURN X+1;
  END
BEGIN
  N = F(5);
  SUSPEND;
END ^
--
-- Sub-function inside a stored function
--
CREATE OR ALTER FUNCTION FUNC1 (n1 INTEGER, n2 INTEGER)
  RETURNS INTEGER
  AS
  DECLARE FUNCTION SUBFUNC (n1 INTEGER, n2 INTEGER)
    RETURNS INTEGER
    AS
    BEGIN
      RETURN n1 + n2;
    END
    BEGIN
      RETURN SUBFUNC(n1, n2);
    END ^
--
select func1(5, 6) from rdb$database ^
      
Prev: PSQL Stored FunctionsFirebird Documentation IndexUp: Procedural SQL (PSQL)Next: Packages
Firebird Documentation IndexFirebird 3.0.6 Release NotesProcedural SQL (PSQL) → PSQL Sub-routines