Mysql语法错误创建存储过程
作者:互联网
这让我疯了.
CREATE DEFINER=`root`@`localhost` PROCEDURE `CalcularCRTarea` (Id_Tarea INT, OUT crTarea decimal(12, 4))
DETERMINISTIC
BEGIN
DECLARE done BOOLEAN DEFAULT FALSE;
DECLARE _id BIGINT UNSIGNED;
DECLARE cur CURSOR FOR SELECT Id FROM Tarea_Frente where Id_Item_Tarea = Id_Tarea;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;
OPEN cur;
testLoop: LOOP
FETCH cur INTO _id;
IF done THEN
LEAVE testLoop;
ELSE
CALL CalcularCRFrente(_id, @suma);
SET crTarea = crTarea + @suma;
END IF;
END LOOP testLoop;
CLOSE cur;
END;
phpmyadmin回复我
MySQL said: Documentation
#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 4
那将是一条线
DECLARE done BOOLEAN DEFAULT FALSE;
这有什么不对?我尝试了几个小的改动,我总是得到同样的错误.我检查了文档,我没有看到语法错误是什么.
我知道这是一个愚蠢的错误,但是我被困了半个小时.
是一个游标,它迭代每一行并为每一行执行存储过程;我已经用存储的函数完成了它(并且它像魅力一样工作)但是当时在服务器中发布我看到我的共享主机不支持存储的函数,只有存储过程:(所以这是我最好的方式’我找到了.
解决方法:
您缺少自定义分隔符指令.
当你错过它时,引擎试图在发现第一个默认语句终止符分号时编译语句.因此例外.
将您的整个例程放在:
-- define the delimiter
delimiter //
--- place here your stored procedure
-- and lastly following line
//
-- reset the delimiter
delimiter ;
标签:mysql-error-1064,sql,mysql,stored-procedures 来源: https://codeday.me/bug/20190929/1833601.html