给定n个数字,任务是在PL / SQL中生成从0到n的斐波那契数字,其中斐波那契整数系列的形式为
0, 1, 1, 2, 3, 5, 8, 13, 21, 34
其中,整数0和1将具有固定的空格,例如,在加上两个数字后,
0+1=1(3rd place) 1+1=2(4th place) 2+1=3(5th place) and So on
斐波那契数列的序列F(n)的递归关系定义为-
Fn = Fn-1 + Fn-2 Where, F(0)=0 and F(1)=1 are always fixed
PL / SQL是一种Oracle产品,它是SQL和90年代初引入的过程语言(PL)的组合。引入它是为了向简单的SQL添加更多的特性和功能。
-- declare variable a = 0 for first digit in a series -- declare variable b = 0 for Second digit in a series -- declare variable temp for first digit in a series declare a number := 0; b number := 1; temp number; n number := 10; i number; begin dbms_output.put_line('fibonacci series is :'); dbms_output.put_line(a); dbms_output.put_line(b); for i in 2..n loop temp:= a + b; a := b; b := temp; dbms_output.put_line(temp); end loop; end;
输出结果
fibonacci series is : 0 1 1 2 3 5 8 13 21 34