BEGIN
DECLARE cflag bit DEFAULT 0;
DECLARE cid int;
declare cname VARCHAR(16);
--声明一个游标
declare cur_copy CURSOR for select id,name from fruit;
--设置游标结束标记
DECLARE CONTINUE HANDLER for not found set cflag=1;
--开启游标
OPEN cur_copy;
--循环取出游标里的值
read_loop:loop
FETCH cur_copy into cid,cname;
--循环结束标记
if cflag=1 then leave read_loop;
end if;
insert into fruit_copy(id,name) values(cid,cname);
end loop;
close cur_copy;
END
时间: 2024-12-18 10:15:03