Oracle: Fibonacci Series by SQL

You can use phi to compute the nth number in the Fibonacci series (fn).
If you consider 0 in the Fibonacci series to correspond to n = 0, use this formula:
fn =  Phi n / 5½

Query to generate 10 fibonacci series numbers
SELECT ROUND(POWER(1.6180339,LEVEL) / POWER(5,0.5)) FROM DUAL CONNECT BY LEVEL < =10

The value of Phi can be calculated as
(1 + sqrt (5))/2 = 1.61803399

So we can rewriet our query as
SELECT ROUND(POWER((1 + sqrt (5))/2,LEVEL) / POWER(5,0.5)) FROM DUAL CONNECT BY LEVEL < =10


Related Links
ORA-01436: CONNECT BY loop in user data
http://nimishgarg.blogspot.in/2011/02/ora-01436-connect-by-loop-in-user-data.html

Connect By Prior (Hierarchical Query)
http://nimishgarg.blogspot.in/2010/02/oracle-connect-by-prior-hierarchical.html

Get All Month or Week Days Names
http://nimishgarg.blogspot.in/2010/01/oracle-sql-get-all-month-names-jan-to.html

Alpha Numeric Counter Or Sequence
http://nimishgarg.blogspot.in/2011/04/alpha-numeric-counter-or-sequence.html

Oracle SQL: Triangular Series (1 3 6 10 15 21)
http://nimishgarg.blogspot.in/2010/07/oracle-sql-triangular-series-1-3-6-10.html

4 comments:

  1. Really Great. Thanks

    ReplyDelete
  2. Replies
    1. Also check related posts of this article.

      Delete
  3. This comment has been removed by a blog administrator.

    ReplyDelete