1
如果發生錯誤(使用SIGNAL),我嘗試在過程中回滾事務。 我有兩個問題:MySQL - 在嵌入式過程的情況下回滾事務
- 欲停止執行聲明1,如果發生錯誤,
- 欲停止執行Stateemtn 2,如果在步驟(1)
過程中發生錯誤1:
CREATE DEFINER=`edgar`@`%` PROCEDURE some_sp (IN param INT)
BEGIN
DECLARE `_rollback` BOOL DEFAULT 0;
DECLARE new_legal_entity_id INT;
DECLARE specialty CONDITION FOR SQLSTATE '45000';
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET _rollback = 1;
START TRANSACTION;
CASE -- Some condition
BEGIN
SIGNAL specialty
SET MESSAGE_TEXT = 'Error message';
END;
ELSE BEGIN END;
END CASE;
INSERT INTO .... -- Statement 1
COMMIT;
END
步驟2:
CREATE DEFINER=`edgar`@`%` PROCEDURE some_sp_1 (IN param INT)
BEGIN
DECLARE `_rollback` BOOL DEFAULT 0;
DECLARE new_legal_entity_id INT;
DECLARE specialty CONDITION FOR SQLSTATE '45000';
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET _rollback = 1;
START TRANSACTION;
CALL some_sp(some_param);
INSERT INTO .... -- Statement 2
COMMIT;
END
不,@wchiquito,這似乎並沒有爲我工作。查看我的回答 –
@ EdgarNavasardyan:[SQL Fiddle](http://sqlfiddle.com/#!9/348340/1),測試正在運行。 – wchiquito