1

我在存储过程中有一个简单的嵌套 while 循环,但它给出了一个错误。该循环并没有什么大不了的,只是为了学习目的,我创建了两个循环。

delimiter $$
create procedure getSum(in input int , out output int)
begin

set output = 0;
while input >= 1 do

  declare tmp int default 1;
  while tmp <= 5 do
      set  output = output + input ;
      set tmp = tmp + 1;
   end while ;

set input = input - 1 ;

end while;

end $$
delimiter ;

下面是错误

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'declare tmp int default 1; while tmp <= 5 do set output = output + inpu' at line 7

谢谢。

4

1 回答 1

0

试试这个:

delimiter $$
create procedure getSum(in input int , out output int)
begin
declare tmp int default 1;
set output = 0;
while input >= 1 do

  set tmp = 1;
  while tmp <= 5 do
      set  output = output + input ;
      set tmp = tmp + 1;
   end while ;

set input = input - 1 ;

end while;

end $$
delimiter ;
于 2012-04-24T13:31:49.160 回答