我正在尝试实现一个存储过程来创建用户余额的快照,并且在第5行中总是出现错误,该语法错误,并且我没有找到该语法错误的答案:
DROP PROCEDURE IF EXISTS createSnapshot;
DELIMITER //
CREATE PROCEDURE createSnapshot()
BEGIN
INSERT INTO balance_history (uid,coin_id,balance) SELECT uid,coin_id,amount FROM balance;
DECLARE done INT DEFAULT FALSE;
DECLARE cursor1 CURSOR FOR SELECT primary_key,timestamp FROM balance_history WHERE timestamp < DATE_SUB(NOW(), INTERVAL 7 DAY);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
DECLARE id INT;
DECLARE time1 TIMESTAMP;
OPEN cursor1;
read_loop: LOOP;
IF done THEN
LEAVE read_loop;
END IF
FETCH cursor1 INTO id,time1;
END LOOP
CLOSE cursor1;
END//
DELIMITER;
答案 0 :(得分:1)
MySQL存储过程,函数等。关于在何处可能存在变量的定义有一些规则。通常,块的开始是最好的。尽管某些类型的局部变量必须在其他类型之后声明。
This是查找特定文档时从MySQL文档开始的很好参考。