Here you will get pl/sql program for fibonacci series.
It is a series in which next number is the sum of previous two numbers.
PL/SQL Program for Fibonacci Series
declare first number:=0; second number:=1; third number; n number:=&n; i number; begin dbms_output.put_line('Fibonacci series is:'); dbms_output.put_line(first); dbms_output.put_line(second); for i in 2..n loop third:=first+second; first:=second; second:=third; dbms_output.put_line(third); end loop; end; /
Output
Enter value for n: 6
old 5: n number:=&n;
new 5: n number:=6;
Fibonacci series is:
0
1
1
2
3
5
8
why 2..n in above program
as we have already printed first and second number, we should use (3..n) to generate 5 terms(0 1 2 3 5).
I want to print series 5,8,12,17,23…
create or replace function fn1 (n in number) return sys_refcursor as
first number:=5;
third number;
i number;
begin
dbms_output.put_line(first);
for i in 3..n
loop
third:=first+i;
first:=third;
dbms_output.put_line((third));
end loop;
end;
/
Thanks for this program. This program is correct program.
I need to create procedure to find Fibonacci series
create or replace function fn1 (n in number) return sys_refcursor as
first number:=0;
second number:=1;
third number;
begin
dbms_output.put_line(‘Fibonacci series is:’);
dbms_output.put_line(first);
dbms_output.put_line(second);
for i in 2..n
loop
third:=first+second;
first:=second;
second:=third;
dbms_output.put_line(third);
end loop;
end;
/