我在Mysql 5.1.73-cll中有以下存储过程:
BEGIN
DECLARE finished1 INTEGER DEFAULT 0;
DECLARE cursor1 CURSOR FOR SELECT ... FROM table1 WHERE Id= 1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished1 = 1;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
CALL Debug('SQLEXCEPTION');
ROLLBACK;
CALL Debug('Rollback executed');
END;
START TRANSACTION;
INSERT INTO table2(...) VALUES (...); /* Statement 1*/
OPEN cursor1;
label1: LOOP
FETCH cursor1 INTO var1, var2;
IF finished1 = 1 THEN
INSERT INTO table1(...) VALUES (...); /* Statement 2*/
LEAVE label1;
END IF;
UPDATE table1 SET ... WHERE Id=1; /* Statement 3*/
LEAVE label1;
END LOOP label1;
CLOSE cursor1;
COMMIT;
END
当我(故意)在语句3中引入SQL错误,并确保finished1 = 0时,我希望回滚语句1,但事实并非如此。 通过我的Debug过程,我知道执行了Rollback语句。所有表都是InnoDb。 我做错了什么?