Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Verschachtelte Schleife in gespeicherter MySQL-Prozedur

Versuchen Sie Folgendes:

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 ;