mysql事务错误处理

时间:2012-02-02 00:33:36

标签: mysql transactions

 DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND 
BEGIN 
    ROLLBACK; 
END;
START TRANSACTION;      

    UPDATE tbl_order SET TransactionID="abc" WHERE OrderID=1;
    UPDATE tbl_order SET TransactionID="xyz" WHERE OrderID=;
    UPDATE tbl_order SET TransactionID="zzz" WHERE OrderID=13;


COMMIT;

由于某种原因,命令1和13被填充而没有回滚,我得到退出hadler的语法错误。

Query:  DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND BEGIN ROLLBACK

Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING, NOT FOUND 
BEGIN 
    ROLLBACK' at line 1
有人可以帮我弄清楚我做错了吗?

提前致谢

修改

UPDATE tbl_order SET TransactionID =“xyz”WHERE OrderID =;

是故意的

1 个答案:

答案 0 :(得分:0)

我相信退出处理程序只能在存储过程中使用。文档没有明确说明这一点,但暗示

  

在存储程序执行期间可能会出现需要特殊处理的条件

http://dev.mysql.com/doc/refman/5.1/en/condition-handling.html