Plsql 使用pl/sql函数的斐波那契级数程序

Plsql 使用pl/sql函数的斐波那契级数程序,plsql,rdbms,Plsql,Rdbms,我必须创建一个函数来打印斐波那契级数作为结果。我在下面的程序中使用了varray,但它在第2行给出了一个错误:“PLS-00201:必须声明标识符‘ARRAY’” create function fibonacci7(x int) return VARRAY is type fib IS VARRAY(25) OF VARCHAR(10); a number(3):=1; b number(3):=1; c number(3); i number(3):=1; begin while a<

我必须创建一个函数来打印斐波那契级数作为结果。我在下面的程序中使用了varray,但它在第2行给出了一个错误:“PLS-00201:必须声明标识符‘ARRAY’”

create function fibonacci7(x int)
return VARRAY
is
type fib IS VARRAY(25) OF VARCHAR(10);
a number(3):=1;
b number(3):=1;
c number(3);
i number(3):=1;
begin
while a<=n
    loop
       fib(i) := a;
       c:=a+b;
       a:=b;
       b:=c;
       i:=i+1;
    end loop;
return codes_;
end ;
/

select fibonacci7(5) from dual;
创建函数fibonacci7(x int)
返回瓦雷
是
fib型为VARCHAR(10)的VARRAY(25);
一个数字(3):=1;
b数(3):=1;
c编号(3);
i编号(3):=1;
开始

而a我想这会满足你的要求。VARRAY的语法与您使用的略有不同

set serveroutput on size 1000000

create or replace type fibtype AS VARRAY(25) OF NUMBER;
/

create or replace function fibonacci7(n number)
return fibtype
is
fib fibtype := fibtype();
a number:=1;
b number:=1;
c number;
i number:=1;
begin
fib.extend(n);
while i<=n
    loop
       fib(i) := a;
       c:=a+b;
       a:=b;
       b:=c;
       i:=i+1;
    end loop;
return fib;
end ;
/

declare
i number;
fib fibtype := fibtype();
begin
fib := fibonacci7(6);
for i in 1..fib.count loop
  dbms_output.put_line(to_char(fib(i)));
end loop;
end;
/
博比


p、 美国修复了fib(6)并制作了数组编号

非常感谢。我相信函数中有一点错误。如果函数调用fibonacci7(n)意味着
获取Fibonacci序列中的前n个值
,则在
1
1
2
3
5
8