Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Generate Fibonaci series Jump to:  
Category: >> Oracle PL/SQL >> Generate Fibonaci series Bookmark and Share

<< lastnext >>

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;


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 210 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?