PL/SQL 中的斐波那契数编程
给定数字‘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 和过程语言 (PL) 的组合,在 90 年代初推出。它被引入以向简单的 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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP