我什至无法让这个基本的 CURSOR LOOP 在我的事务中运行。
请帮忙。提前致谢!
CREATE PROCEDURE ClearItems(IN itemName CHAR)
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE bID INT(255);
DECLARE bIDs CURSOR FOR SELECT id FROM table1 WHERE column1 = itemName AND column2 = 'b' ORDER BY column3 DESC, date ASC;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
START TRANSACTION;
OPEN bIDs;
clear_loop: LOOP
FETCH bIDs INTO bID;
IF done THEN
LEAVE clear_loop;
END IF;
INSERT INTO table2 (column1) SELECT bID;
END LOOP;
CLOSE bIDs;
COMMIT;
END //
DELIMITER ;