程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> MySQL存儲過程SAVEPOINT ROLLBACK to_MySQL教程

MySQL存儲過程SAVEPOINT ROLLBACK to_MySQL教程

編輯:關於MYSQL數據庫

 MySQL存儲過程SAVEPOINT ROLLBACK to
示例如下:

DELIMITER $$


DROP PROCEDURE IF EXISTS `test`.`handlerdemo`$$


CREATE DEFINER=`root`@`localhost` PROCEDURE `handlerdemo`()

BEGIN

DECLARE X2 INT;

DECLARE CONTINUE HANDLER FOR SQLWARNING SET X2= 1;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET X2 = 2;

DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET X2= 3;

DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET X2 = 4;

START TRANSACTION;

SAVEPOINT savepoint_1;

BEGIN

INSERT INTO eugene VALUES (1);

INSERT INTO eugene VALUES (2);

SELECT X2;

end;

ROLLBACK TO SAVEPOINT savepoint_1;

iNSERT INTO eugene VALUES (3);

END$$


DELIMITER ;


#測試表

CREATE TABLE `eugene` (

t1` int(4) default NULL

)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved