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
4 comments:
awesome and simple code
nice and really helpful article to everyone... thanks for sharing
Internet Marketing Company Chennai
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;
/
declare
n number:=&n;
p1 number :=0;
p2 number :=1;
p3 number;
begin
dbms_output.put_line(p1);
dbms_output.put_line(p1);
for i in 3..n
loop
p3:= p1+p2;
dbms_output.put_line(p3);
p1:=p2;
p2:=p3;
end loop;
exception
when others
then
dbms_output.put_line(sqlerrm);
end;
/
Post a Comment
Dont SPAM