Saturday, November 12, 2011

PL/SQL program to generate Fibonacci series

It is a sample example of generate fibonacci series upto 10 numbers.

Aim - PL/SQL program to generate Fibonacci series.



PLSQL Sample Program: -

declare
f1 number(3);
f2 number(3);
f3 number(3);
num number(3);
begin
f1:=0;
f2:=1;
f3:=0;
num:=1;
while num<=10
loop
dbms_output.put_line(f3);
f1 :=f2;
f2:=f3;
f3:=f1+f2;
num:=num+1;
end loop;
end;




Output of PL SQL Block: -
0
1
1
2
3
5
8
13
21
34

3 comments:

anoop lalli said...

awesome and simple code

manigandan busy said...

nice and really helpful article to everyone... thanks for sharing
Internet Marketing Company Chennai

Unknown said...

declare
i number(3):=1;
j number(3):=1;
temp number(3):=1;
begin
dbms_output.put_line(i);
dbms_output.put_line(j);
loop
i:=i+j;
j:=temp;
temp:=i;
dbms_output.put_line(i);
exit when i>50;
end loop;
end;
/

Post a Comment

Dont SPAM