# PLSQL Program to find Fibonacci Series

In this article, we will see how to write PLSQL Program to find Fibonacci Series. As per the portrayal of the Fibonacci series, first, two math are 0 and 1 and each later number is the sum of the precedent two math in the series. Fibonacci series. Following are the places where we can implement the Fibonacci series

• MERGE sort
• Search Algorithms
• Network Topology
• Lossy compression in Data encoding, Streaming Media, and internet telephony.

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 the sum of the previous two.

0,1,1,2,3,5,8,13,21,34,55…

For your better understanding, I have represented a diagram that shows the Fibonacci Series.

You can observe the lines which are in red color when you calculate the sub diagonally which gives you the series of numbers that we are expecting here.

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
``````

## Output

``0,1,1,2``

### Conclusion

The Fibonacci sequence is one of the most prominent formulas in mathematics. Each number in the sequence is the sum of the two figures that forego it. So, the sequence goes 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on. The hairline equation describing its Xn 2 = Xn 1