问题遇到的现象和发生背景
根据题目:计算从1到n之间偶数的累加值,n为传入的参数值
编写sql语句,发现创建失败,但是自己检查了,是没有问题的,
所有想知道错误在哪?
问题相关代码,请勿粘贴截图
create procedure p12(in n int)
begin
declare total int default 0;
sum: loop
if n%2 = 1 then
set n := n-1;
iterate sum;
end if;
IF n<=0 THEN
LEAVE sum;
END IF;
set total := total + n;
set n := n-1;
end loop sum;
select total;
end;
运行结果及报错内容
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 '' at line 19