| 導購 | 订阅 | 在线投稿
分享
 
 
 

MySQL存儲過程SAVEPOINT ROLLBACK to

來源:互聯網  2008-06-01 02:56:55  評論

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

)

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 )
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有