存储过程:异常处理continue

论坛 期权论坛 脚本     
匿名技术用户   2020-12-22 02:40   62   0
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 |
+------+------+
*/

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP