I am new to MySQL procedures. 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:
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. Afterwards, you restore the standard delimiter and go on as usual.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.