当前位置:Gxlcms > mysql > MySQL事务ROLLBACK示例代码

MySQL事务ROLLBACK示例代码

时间:2021-07-01 10:21:17 帮助过:5人阅读

无详细内容 事务 ROLLBACK MySQL mysqlmysql delimiter $$mysqlmysql CREATE PROCEDURE myProc( - in_from INTEGER, - in_to INTEGER, - in_amount DECIMAL(8,2)) - BEGIN - - DECLARE txn_error INTEGER DEFAULT 0 ; - - DECLARE CONTINUE HANDLER FOR SQLEX

<无详细内容> 事务 ROLLBACK MySQL
mysql>
mysql> delimiter $$
mysql>
mysql> CREATE PROCEDURE myProc(
    ->   in_from INTEGER,
    ->   in_to   INTEGER,
    ->   in_amount DECIMAL(8,2))
    -> BEGIN
    ->
    ->   DECLARE txn_error INTEGER DEFAULT 0 ;
    ->
    ->   DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN
    ->     SET txn_error=1;
    ->   END;
    ->
    ->   SAVEPOINT savepoint_tfer;
    ->
    ->   UPDATE employee
    ->      SET salary=in_amount
    ->    WHERE id=in_from;
    ->
    ->   IF txn_error THEN
    ->     ROLLBACK TO savepoint_tfer;
    ->     SELECT 'Transfer aborted ';
    ->   ELSE
    ->     UPDATE employee
    ->        SET salary=in_amount
    ->      WHERE id=in_to;
    ->
    ->      IF txn_error THEN
    ->         ROLLBACK TO savepoint_tfer;
    ->         SELECT 'Transfer aborted ';
    ->      END IF;
    ->   END IF;
    ->
    -> END$$
Query OK, 0 rows affected (0.00 sec)

人气教程排行