在写存储过程,运行后提示“Incorrect number of FETCH variables”
原来是用游标select的字段数需要与fetch into的变量数一致
修改后的如下:
DROP PROCEDURE IF EXISTS modify_recommend_merchant;
DELIMITER //
CREATE PROCEDURE modify_recommend_merchant()
BEGIN
DECLARE dat DATETIME DEFAULT DATE_SUB(NOW(), INTERVAL 1 DAY);
DECLARE m_id INT;
DECLARE done INT DEFAULT 0;
DECLARE cur CURSOR FOR SELECT merchant_id FROM merchant WHERE is_recommend = 1 AND biz_type = 1 AND STATUS = 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
l1:LOOP
FETCH cur INTO m_id;
IF done = 1 THEN
LEAVE l1;
END IF;
SET dat = DATE_ADD(dat, INTERVAL 1 SECOND);
UPDATE merchant SET recommend_time = dat WHERE merchant_id = m_id;
END LOOP l1;
CLOSE cur;
END//
DELIMITER ;
CALL modify_recommend_merchant;