7. PL/SQL Program for Fibonacci Series
DELIMITER $$
CREATE PROCEDURE fibonacci(IN `c` INT )
BEGIN
declare n int;
declare i int;
set n=0;
set i=0;
CREATE TEMPORARY TABLE Numbers (Num int);
Insert Into Numbers VALUES(0),(1);
WHILE c>0 DO
SET @n = (SELECT sum(Num) from (Select Num from Numbers order by Num DESC LIMIT 2) AS T);
Insert Into Numbers VALUES(@n);
Set @i = (Select count(*) from Numbers);
set c=c-1;
END WHILE;
SELECT Num FROM numbers;
DROP TABLE numbers;
END$$
DELIMITER ;
call fibonacci(5);
0 Comments
If you have any doubts/suggestion/any query or want to improve this article, you can comment down below and let me know. Will reply to you soon.