from Error Handler Examples Here are some examples of handler declarations: If any error condition arises (other than a NOT FOUND ), continue execution after setting l_error=1 : DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET l_error=1; If any error condition arises (other than a NOT FOUND ), exit the current block or stored program after issuing a ROLLBACK statement and issuing an error message: DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; SELECT 'Error occurred ? terminating'; END; If MySQL error (duplicate key value) is encountered, continue execution after executing the SELECT statement (which generates a message for the calling program): DECLARE CONTINUE HANDER FOR 2 SELECT 'Duplicate key in index'; If SQLSTATE (duplicate key value) is encountered, continue execution after executing the SELECT statement (which generates a message for the calling program): DECLARE CONTINUE HANDER FOR SQLSTATE '' SELECT 'Duplicate key in index'; When a cursor fetch or SQL retrieves no values, continue execution after setting l_done=1 : DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_done=1; Same as the previous example, except specified using a SQLSTATE variable rather than a named condition: DECLARE CONTINUE HANDLER FOR SQLSTATE ' ' SET l_done=1; Same as the previous two examples, except specified using a MySQL error code variable rather than a named condition or SQLSTATE variable: DECLARE CONTINUE HANDLER FOR SET l_done=1; 错误处理例子 有几种错误处理的声明形式: § 如果任何错误(不是 NOT FOUND ) , 设置 l_error 为 1 后继续执行: DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET l_error=1; § 如果发生任何错误(不是 NOT FOUND), 执行 ROLLBACK和产生一条错误消息后退出当前块或存储过程。 DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; SELECT 'Error occurred ? terminating'; END; § 如果 MySQL 错误 (重复的健值 )发生,执行 SELECT语句(向调用程序发一条消息)后继续执行 DECLARE CONTINUE HANDER FOR 2 SELECT 'Duplicate key in index'; § 如果 SQLSTATE 错误 (重复的健值 )发生,执行 SELECT语句(向调用程序发一条消息)后继续执行 DECLARE CONTINUE HANDER FOR SQLSTATE '' SELECT 'Duplicate key in index'; § 当游标或者 SQL 选择语句没有返回值时,设置 l_done=1 后继续执行 DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_done=1; § 此例除了用 SQLSTATE 变量而不是命名条件以外,跟前一个例子一样 DECLARE CONTINUE HANDLER FOR SQLSTATE ' ' SET l_done=1; § 此例除了用 MySQL 的错误码变量而不是命名条件或者 SQLSTATE 变量以外,跟前两个例子一样 DECLARE CONTINUE HANDLER FOR SET l_done=1;
推荐整理分享MySQL 错误处理例子[译](mysql错误代码大全),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:mysql错误代码大全,mysql常见故障和解决方法,mysql 错误码大全,mysql常见错误,mysql错误代码大全,mysql常见错误,mysql常见错误,mysql错误大全,内容如对您有帮助,希望把文章链接给更多的朋友!
mysql 日期和时间格式转换实现语句 这里是一个使用日期函数的例子。下面的查询选择了所有记录,其date_col的值是在最后天以内:mysqlSELECTsomethingFROMtableWHERETO_DAYS(NOW())-TO_DAYS(date_col)=;DAY
MySQL 数据类型 详解 1、整型MySQL数据类型含义(有符号)tinyint(m)1个字节范围(-~)smallint(m)2个字节范围(-~)mediumint(m)3个字节范围(-~)int(m)4个字节范围(-
提高MySQL中数据装载效率 相对来说,将数据装入数据库是直截了当的。然而,也存在可用来改善数据装载操作效率的策略,其基本原理如下:成批装载较单行装载更快,因为在