56,677
社区成员
发帖
与我相关
我的任务
分享
drop table if exists testinfo;
create table testinfo
(
name varchar(10) not null,
age int
);
truncate table testinfo;
insert into testinfo() values('you',15);
insert into testinfo() values('me',20);
drop procedure if exists test_proc;
delimiter //
create procedure test_proc()
begin
DECLARE done int default false;
DECLARE a char(10);
DECLARE b int;
DECLARE cur1 cursor for select name,age from testinfo ;
DECLARE continue handler for SQLSTATE '02000' set done = true;
open cur1;
read_loop: loop
FETCh cur1 into a,b;
if done then
leave read_loop;
end if;
select @a,@b;
insert into testinfo values(@a,@b);
end loop;
close cur1;
end
//
delimiter ;
call test_proc();