drop table if exists t2;
create table t2
(
s1 int, primary key (s1)
)
engine=innodb;
delete from t2;
drop procedure if exists p23;
delimiter //
create procedure p23()
begin
declare continue handler
for sqlstate '23000' set @x2 = 1;
set @x = 1;
insert into t2 values (1);
set @x = 2;
insert into t2 values (1);
set @x = 3;
end;//
delimiter ;
call p23();
select @x, @x2;
/*
3000SQLSTATE是更常用的,当外键约束出错或主键约束出错就被调用了
MySQL允许两种处理器,一种是EXIT处理,我们刚才所用的就是这种。另一种就是我们将要演示的,CONTINUE处理,
它跟EXIT处理类似,不同在于它执行后,原主程序仍然继续运行
+------+------+
| @x | @x2 |
+------+------+
| 3 | 1 |
+------+------+
*/
存储过程:异常处理continue
最新推荐文章于 2023-11-26 18:54:28 发布