Fibonacci Numbers are the sequence of numbers starting with zero and one. In this article, we will see how to write a PLSQL Program to find the Fibonacci series.
For each of the following is sum of the previous two.
The Fibonacci Series Formula is given below
Fn = Fn-1 + Fn-1
With the selected values
F0=0 and F1 is 1
Given a number n to print nth Fibonacci Number.
Input : n = 3 Output : 5 Input : n = 4 Output : 7
Below is the required implementation to get the Fibonacci number series in PLSQL
declare -- declare variable first_number = 0, -- second_number = 1 and temp of datatype number first_number := 0; second_number := 1; temp_number; n number := 4; i number; begin dbms_output.put_line('Fibonacci Series:'); --print first two term first_number and second_number dbms_output.put_line(first_number); dbms_output.put_line(second_number); -- loop i = 2 to n for i in 2..n loop temp:=first_number+second_number; first_number := second_number; second_number := temp_number; --To print terms of fibonacci series dbms_output.put_line(temp_number); end loop; end; --Program End