MySQL事物和游标示例

--事务
START TRANSACTION;
SELECT name FROM first WHERE age=23;
SAVEPOINT one;
SELECT age FROM first WHERE name='Lucy';
SAVEPOINT two;
ROLLBACK;

--游标
DROP PROCEDURE IF EXISTS showname;       
DELIMITER $
CREATE PROCEDURE showname()
BEGIN
	DECLARE done BOOLEAN DEFAULT 0;
	DECLARE tname VARCHAR(10) DEFAULT '';
	DECLARE curl CURSOR
	FOR
	SELECT name FROM first;
	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done=1;
	OPEN curl;
REPEAT
	FETCH curl INTO tname;
	INSERT INTO t(name) VALUES(tname);
	UNTIL done END REPEAT;
	CLOSE curl;
END $
DELIMITER ;

你可能感兴趣的:(MySQL事物和游标示例)