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 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>
更多精彩
赞助商链接