无法在触发器中使用每个循环 我正在
错误代码:1064
DELIMITER $$
CREATE
TRIGGER `TRG_AU_DEVICES_HOWLONG` AFTER UPDATE ON `devices`
FOR EACH ROW BEGIN
DECLARE lastid INTEGER;
DECLARE a, b, c VARCHAR(255);
SET @lastid := (SELECT deviceId FROM devices ORDER BY packetDate DESC LIMIT 1);
DECLARE cur1 CURSOR FOR SELECT alertType,deviceId FROM alerts WHERE alerts.deviceId = @lastid ;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO a, b;
insert into test(alertType,deviceId) values(a,b);
END LOOP;
CLOSE cur1;
END;
$$
DELIMITER ;
无法在触发器中使用每个循环,我得到Error Code: 1064
。如何在触发器中使用每个循环
答案 0 :(得分:0)
DELIMITER $$
CREATE
TRIGGER TRG_TEST
更新devices
之前
为了每行开始
DECLARE完成INT DEFAULT 0;
DECLARE alert VARCHAR(255);
DECLARE my_cur CURSOR FOR SELECT alertType FROM alerts WHERE deviceId = 8170610948; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; 打开my_cur; my_cur_loop: LOOP FETCH my_cur INTO a; 如果完成= 1那么 离开my_cur_loop; 万一; INSERT INTO test(alertType)VALUES(alert); END LOOP my_cur_loop; 关闭my_cur;
END; $$