WEB开发网
开发学院数据库MySQL MySQL数据库的异常处理 阅读

MySQL数据库的异常处理

 2010-09-06 15:58:51 来源:WEB开发网   
核心提示:遇到错误继续的情况mysql> truncate table t;Query OK, 0 rows affected (0.01 sec)mysql> DELIMITER $$mysql> drop PROCEDURE IF exists `t_girl`.`handlerdemo`$$Query O

遇到错误继续的情况

mysql> truncate table t;
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER $$
mysql> drop PROCEDURE IF exists `t_girl`.`handlerdemo`$$
Query OK, 0 rows affected (0.00 sec)
mysql> create DEFINER=`root`@`localhost` PROCEDURE `handlerdemo`()
-> BEGIN
-> DECLARE CONTINUE HANDLER FOR SQLSTATE ’23000’ BEGIN END;
-> SET @x = 1;
-> insert INTO t VALUES (1);
-> SET @x = 2;
-> insert INTO t VALUES (1);
-> SET @x = 3;
-> END$$
Query OK, 0 rows affected (0.01 sec)
mysql> DELIMITER ;
mysql> call handlerdemo();
Query OK, 0 rows affected (0.00 sec)
mysql> select @x;
+------+
| @x |
+------+
| 3 |
+------+
1 row in set (0.00 sec)
mysql> call handlerdemo();
Query OK, 0 rows affected (0.00 sec)
mysql> select @x;
+------+
| @x |
+------+
| 3 |
+------+
1 row in set (0.00 sec)
mysql>

Tags:MySQL 数据库 异常

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接