delimiter //
drop procedure if exists `test` //
CREATE PROCEDURE `test`() comment '测试存储过程'
BEGIN
declare a varchar(255);
declare i int(1) default 0;
DECLARE cur CURSOR FOR select tname from `test`;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION ,NOT FOUND
rollback;
start transaction;
OPEN cur;
while i<12 do
FETCH cur INTO a;
insert into `test` (tname) values (a);
set @ret=row_count();
if @ret<=0 then
rollback;
end if;
set i=i+1;
end while;
close cur;
commit;
end //
delimiter ;
call test();
本文转自 Lee_吉 博客,原文链接: http://blog.51cto.com/12173069/1982075 如需转载请自行联系原作者