SQL Model Iteration - Hemachandra/Fibonacci Sequence

-- f(n) = f(n-1) + f(n-2)
-- Where n=1 is 0, n=2 is (1+0) and so on.

SELECT val No, fsq fibonacci_seq
FROM DUAL
 MODEL RETURN ALL ROWS
 DIMENSION BY ( 0 d )
 MEASURES (0 AS fsq,
           0 AS val
          )
 RULES ITERATE (18)
 (
  fsq[iteration_number] = DECODE(iteration_number, 0, 0, 1, 1,
                           fsq[iteration_number-2]) + nvl(fsq[iteration_number-1],0),
  val[iteration_number] = iteration_number+1
);

SQL Model Iteration - Fibonacci Sequence

Oracle 11g Function - Fibonacci Sequence

Math Reference

Oracle registered trademark of Oracle Corporation.

Last Revised On: November 17th, 2013

  361