# Program for Fibonacci numbers in PL/SQL

PL/SQLDatabaseBig Data Analytics

Given with ‘n’ numbers the task is to generate the fibonacci numbers in PL/SQL starting from 0 to n where fibonacci series of integer is in the form

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

Where, integer 0 and 1 will have fixed space, after that two digits are added for example,

0+1=1(3rd place)
1+1=2(4th place)
2+1=3(5th place) and So on

Sequence F(n) of fibonacci series will have recurrence relation defined as −

Fn = Fn-1 + Fn-2
Where, F(0)=0 and F(1)=1 are always fixed

PL/SQL is an Oracle product which is a combination of SQL and Procedural language(PL) introduced in early 90’s. It was introduced for adding more features and functionalities to the simple SQL.

## Exmaple

   -- declare variable a = 0 for first digit in a series
-- declare variable b = 0 for Second digit in a series
-- declare variable temp for first digit in a series
declare
a number := 0;
b number := 1;
temp number;
n number := 10;
i number;
begin
dbms_output.put_line('fibonacci series is :');
dbms_output.put_line(a);
dbms_output.put_line(b);
for i in 2..n
loop
temp:= a + b;
a := b;
b := temp;
dbms_output.put_line(temp);
end loop;
end;

## Output

fibonacci series is : 0 1 1 2 3 5 8 13 21 34
Updated on 20-Sep-2019 14:39:12