Hi,
I need to use recursivity in DB2 functions and procedures.
Example:
CREATE FUNCTION fibonacci(
number integer
)
RETURNS integer
NO EXTERNAL ACTION NOT DETERMINISTIC READS SQL DATA
BEGIN ATOMIC
IF number = 0 OR number = 1 THEN
RETURN 1;
ELSE
RETURN fibonacci(number - 1) + fibonacci(number - 2);
END IF;
END;
Execution result:
SQLSTATE 42884
When a function or procedure calls other routines, the creation order must be ascending, from the most sheltered one to which makes first call. But in recursivity case it enters conflict, due to the called routine, which must exist, is the same one that contains the call.
How can recursivity be used in DB2 functions or procedures?