长夜漫漫,无心睡眠。就写个九九表玩玩吧
delimiter // ##将语句的结束符号从分号;临时改为两个//(可以是自定义)
create procedure t11() ##声明创建存储过程
begin #存储过程开始
declare a int; #声明变量类型
declare b int;
declare c Nvarchar(1000);
create table if not exists test3(id int,id1 int,id2 int,id3 int,id4 int,id5 int,id6 int,id7 int,id8 int,id9 int);
truncate table test3; #是为了在第二次调用存储过程时将前面的数据清空
set a=1;
while a<=9 do
set b=1;
insert into test3 values(a,0,0,0,0,0,0,0,0,0);
while b<=a do
set c =concat(‘id’,b);
set @sqlStr=concat('update test3 set ‘,c,’ = ‘,a*b,’ where id = ',a);
PREPARE msql from @sqlStr; #声明预处理语句
EXECUTE msql; #调用执行预处理语句
set b=b+1;
end while;
set a=a+1;
end while;
select id1,id2,id3,id4,id5,id6,id7,id8,id9 from test3;
truncate table test3;
end// #存储过程结束
delimiter ; ###将语句的结束符号改回分号
call t11();<