begin
DECLARE s_id int;
DECLARE s_name varchar(128);
DECLARE no_more_departments int;
DECLARE typeID int;
DECLARE cur CURSOR FOR SELECT brand_id,brand_name FROM t_article_serial where type_id=1 group by brand_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_departments=1; #当读到数据的最后一条时,设置no变量为1
SET no_more_departments=0; #初始化变量no为0
set typeID = (select id from core_ctype where name ="轮胎品牌");
OPEN cur; #打开游标
while no_more_departments=0 do #判断是不是到了最后一条数据
fetch cur into s_id,s_name; #读取游标中的数据一一复给变量o。
delete from core_obj_backup where id = s_id;
insert into core_obj_backup values (s_id,0,s_name,1,typeID,1,NOW(),null,null);#这个不用解释了吧
end while;
close cur;#最后关闭游标.游标里面存放了那么多数据总是要清理掉的吧。
end
Mysql 游标操作-进阶
最新推荐文章于 2023-06-06 11:01:47 发布