Any better Fibonacci series generator using pure Oracle SQL?

前端 未结 3 2018
清酒与你
清酒与你 2021-01-19 23:08

I wonder if there is any way to generate Fibonacci numbers that beat in simplicity and efficiency this one I wrote:

WITH d (seq) AS
       (SELECT     LEVEL
         


        
3条回答
  •  面向向阳花
    2021-01-19 23:32

    on the simplicity side of things, the query can rely on the built in features (ITERATE () and ITERATION_NUMBER) of MODEL:

    select * from dual
    model
      dimension by (0 seq)
      measures (0 val)
      rules iterate (195) 
      (
         val[iteration_number] = val[iteration_number-1] + val[iteration_number-2],
         val[2] = 1, 
         val[1] = 0, 
         val[0] = 0
      )
    ;
    

提交回复
热议问题