Any better Fibonacci series generator using pure Oracle SQL?

前端 未结 3 2017
清酒与你
清酒与你 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:27

    You can use a recursive sub-query factoring clause:

    WITH fib ( lvl, value, next ) AS (
      SELECT 1, 0, 1
      FROM DUAL
    UNION ALL
      SELECT lvl + 1, next, value + next
      FROM fib
      WHERE lvl < 195
    )
    SELECT lvl, value FROM fib
    

提交回复
热议问题