mysql – ERROR 1305(42000):SAVEPOINT …不存在
作者:互联网
我在我的MYSQL DB中有这个SQL(sproc有空体,所以我猜没有隐式提交?).
DROP PROCEDURE IF EXISTS doOrder;
DELIMITER $$
CREATE PROCEDURE doOrder(IN orderUUID VARCHAR(40))
BEGIN
SAVEPOINT sp_doOrder;
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK TO sp_doOrder;
-- doing my updates and selects here...
END;
RELEASE SAVEPOINT sp_doOrder;
END $$
DELIMITER ;
当我
call doOrder('some-unique-id');
我得到:ERROR 1305(42000):SAVEPOINT sp_doOrder不存在.
我可能会忽略一些事情……任何想法?
解决方法:
您必须使用START TRANSACTION而不是BEGIN来启动存储过程中的事务.
此外,您可能需要将SAVEPOINT语句移动到DECLARE之后(取决于您放置START TRANSACTION的位置)
Note
Within all stored programs (stored procedures and functions, triggers,
and events), the parser treats BEGIN [WORK] as the beginning of a
BEGIN … END block. Begin a transaction in this context with START
TRANSACTION instead.
参见:http://dev.mysql.com/doc/refman/5.6/en/commit.html
标签:mysql,savepoints 来源: https://codeday.me/bug/20190624/1281650.html