【发布时间】:2011-05-31 21:35:11
【问题描述】:
我正在尝试使用 MySQL 中的保存点,但似乎出了点问题。
我收到如下所示的错误:
错误 1305 (42000):保存点 sp_prc_work 不存在
我的程序有或没有保存点的工作方式完全相同。我所期望的是值'4','pqr'不应该出现在表格中,因为 整个事务将被回滚。但是插入了 3 个和 4 个 ID。我明白为什么条目 '3', 'pqr' 在那里,但我猜 id '4' 不应该在那里。
drop table if exists test.savepoint_test;
drop procedure if exists second_fail;
drop procedure if exists prc_work;
CREATE TABLE test.savepoint_test (
id int not null default '0',
name varchar(100),
primary key (id)
)engine=InnoDB;
insert into test.savepoint_test values ('1', 'abc');
insert into test.savepoint_test values ('2', 'xyz');
select * from test.savepoint_test;
delimiter $$
CREATE PROCEDURE second_fail()
BEGIN
INSERT into test.savepoint_test values ('3', 'pqr');
INSERT into test.savepoint_test values ('2', 'mnp');
END;
$$
CREATE PROCEDURE prc_work()
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK TO sp_prc_work;
SAVEPOINT sp_prc_work;
INSERT into test.savepoint_test values ('4', 'pqr');
INSERT into test.savepoint_test values ('2', 'mnp');
END;
$$
delimiter ;
call second_fail();
select * from test.savepoint_test;
call prc_work();
select * from test.savepoint_test;
【问题讨论】:
标签: mysql