CREATE OR REPLACE PROCEDURE FIBONACCI(P_N IN INT, P_FB OUT INT)
IS
V_N2 INT:=0;
V_N1 INT:=1;
V_N INT;
i INT:=1;
BEGIN
LOOP
P_FB:= V_N1+V_N2;
V_N2:=V_N1;
V_N1:=P_FB;
i:=i+1;
EXIT WHEN i>=P_N;
END LOOP;
IF P_N=0 THEN P_FB :=0;
END IF;
END;
Teste da procedure com o número 45.
SET SERVEROUTPUT ON;
DECLARE
v_FIBO INTEGER;
BEGIN
FIBONACCI(45,v_FIBO);
dbms_output.put_line(v_FIBO);
END;