Snippet Name: Generate Fibonaci series
Description: For math users: produce the numbers of the Fibonaci series.
Comment: (none)
Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: February 27th, 2009
|
CREATE OR REPLACE PROCEDURE fib AS
fib_var VARCHAR2(1000);
i INTEGER;
fib_num NUMBER;
fib_num1 NUMBER;
fib_num2 NUMBER;
start_var NUMBER;
count_var NUMBER;
BEGIN
/*
select 50 - to_number(to_char(sysdate, 'DD'))
into start_var
from dual;
*/
start_var := 9;
count_var := 11;
DELETE FROM jwc_fib;
fib_num1 := 1;
fib_num2 := 2;
fib_var := TO_CHAR(fib_num1)||to_char(fib_num2);
FOR i IN 1.. 25
LOOP
fib_num := fib_num1+fib_num2;
fib_var := fib_var || TO_CHAR(fib_num);
fib_num1 := fib_num2;
fib_num2 := fib_num;
END LOOP;
INSERT INTO jwc_fib field1
--values (substr(fib_var,start_var,count_var));
VALUES (fib_var); -- this will output 25 iterations of the fibonaci series
COMMIT;
--could have the fib_nums (instead of the start and count vars) as input based on month, day, etc.
END fib; |