斐波那契序列
又称黄金分割数列、因数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,
故又称为“兔子数列”,指的是这样一个数列:1、1、2、3、5、8、13、21、34、
要求如下;
1. 首先创建一个表,表名是tbl_Fibonacci,表中有两个字段,一个是主键id,数字类型,递增自动生成,第二个字段是num,存储斐波那契数字,2. 在存储过程中
2.1 首先清空tbl_Fibonacci表中的数据
2.2 在表中插入斐波那契数列的前100项值
create table tbl_Fibonacci
( id int auto_increment,
num int,
primary key(id)
)
truncate table tbl_Fibonacci;
create procedure feibo6()
begin
-- truncate table tbl_Fibonacci;
declare yi int default 0;
declare er int DEFAULT 1;
declare qita int;
declare n int;
set n=1;
insert into tbl_Fibonacci (num) values(yi);
insert into tbl_Fibonacci (num) values(er);
while n<101 do
set qita=yi+er;
set yi=er;
set er=qita;
insert into tbl_Fibonacci(num) values( er);
set n=n+1;
end while;
end;
call feibo6();
select * from tbl_Fibonacci;
数据太大没全部存下