
要在MySQL存储过程中执行ROLLBACK,必须在存储过程中声明退出处理程序. MySQL存储过程中有两种类型的处理程序.

sqlexceptionsqlwarning

在执行任何查询且过程中发生任何错误时,将执行SQLException. 在MySQL存储过程中执行时mysql怎么调用存储过程,SQLWarning将执行任何警告. 让我们看看如何在存储过程中使用这些块.

DELIMITER $$
CREATE PROCEDURE `transaction_sp` ()
BEGIN
DECLARE exit handler for sqlexception
BEGIN
-- ERROR
ROLLBACK;
END;
DECLARE exit handler for sqlwarning
BEGIN
-- WARNING
ROLLBACK;
END;
START TRANSACTION;
-- ADD option 5
INSERT INTO product_option(product_id,option_id,required) VALUES(insertedProductID,5,0);
SET poid = (SELECT LAST_INSERT_ID());
INSERT INTO product_option_value(product_option_id,product_id,option_id,option_value_id,quantity,subtract,price,price_prefix,points,points_prefix,weight,weight_prefix) VALUES(poid,insertedProductID,5,50,0,0,4.99,'+',0,'+',0,'+');
-- ADD option 12
INSERT INTO product_option(product_id,option_id,required) VALUES(insertedProductID,12,1);
-- ADD option 13
INSERT INTO product_option(product_id,option_id,required) VALUES(insertedProductID,13,0);
COMMIT;
END
$$

MySQL存储过程中的事务要在MySQL存储过程中执行ROLLBACK,我们必须在存储过程中声明退出处理程序. MySQL存储过程中有两种类型的处理程序. sqlexception sqlwarning SQLException将在有查询执行时执行mysql怎么调用存储过程,并且在此过程中什么也没有发生...
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-159461-1.html
发财的人当然不是常人