简体   繁体   English

存储过程定义上的MySQL错误1064

[英]MySQL Error 1064 on Stored Procedure Definition

I am new to MySQL procedures. 我是MySQL程序的新手。 I am simply trying to run a cursor over a data set and for each row run a different procedure (one I happen to know works). 我只是试图在数据集上运行一个游标,然后为每一行运行一个不同的过程(我碰巧知道它的工作原理)。 I am getting error code 1064 on line three of the below: 我在下面的第三行中收到错误代码1064:

CREATE PROCEDURE `safecycle`.`sp_aggregateAllPORDaily` ()
BEGIN
  DECLARE done INT DEFAULT FALSE;
  DECLARE porID SMALLINT UNSIGNED;
  DECLARE cur1 CURSOR FOR SELECT ID FROM point_of_recycle;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

  OPEN cur1;

  read_loop: LOOP
    FETCH cur1 INTO porID;
    IF done THEN
      LEAVE read_loop;
    END IF;
    CALL sp_aggregatePORDaily(porID);
  END LOOP;

  CLOSE cur1;
END

I have been banging my head against the wall for a while and would very much appreciate some help. 我将头撞在墙上已经有一段时间了,非常感谢您的帮助。

You haven't changed your delimiter, so the first ; 您尚未更改定界符,因此第一个; encountered terminates the entire statement. 遇到终止整个语句。

DELIMITER $$

CREATE PROCEDURE
    blah blah blah
END$$

DELIMITER ;

By changing the delimiter this way, you can safely define your multi-statement procedure, embedding the normal ; 通过以这种方式更改定界符,您可以安全地定义您的多语句过程,并嵌入法线; within it, and then end the create statement with the 'new' delimiter. 在其中,然后以'new'分隔符结束create语句。 Afterwards, you restore the standard delimiter and go on as usual. 之后,您将还原标准定界符并照常进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM