Examples of Sub-Functions
-
Sub-function within a stored function
CREATE OR ALTER FUNCTION FUNC1 (n1 INTEGER, n2 INTEGER) RETURNS INTEGER AS - Subfunction DECLARE FUNCTION SUBFUNC (n1 INTEGER, n2 INTEGER) RETURNS INTEGER AS BEGIN RETURN n1 + n2; END BEGIN RETURN SUBFUNC (n1, n2); END
-
Recursive function call
execute block returns (i integer, o integer) as -- Recursive function without forward declaration. declare function fibonacci(n integer) returns integer as begin if (n = 0 or n = 1) then return n; else return fibonacci(n - 1) + fibonacci(n - 2); end begin i = 0; while (i < 10) do begin o = fibonacci(i); suspend; i = i + 1; end end