この基本的なCURSORLOOPをTRANSACTIONで実行することすらできません。
助けてください。前もって感謝します!
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 ;