BEGIN
#创建接收游标数据的变量
declare i varchar(11);
declare n varchar(20);
declare c int;
#创建总数变量
declare total int default 0;
#创建结束标志变量
declare done int default false;
#创建游标
declare cur cursor for select id,name,count from store where name = 'iphone';
#指定游标循环结束时的返回值
declare continue HANDLER for not found set done = true;
#设置初始值
set total = 0;
#打开游标
open cur;
#开始循环游标里的数据
read_loop:loop
set total = total + 1;
#根据游标当前指向的一条数据
fetch cur into i,n,c;
#判断游标的循环是否结束
if done then
leave read_loop; #跳出游标循环
end if;
#获取一条数据时,将count值进行累加操作,这里可以做任意你想做的操作,
#set total = total + c;
##update store
## set count =i
## where id=i; #i只有三次,所以也只有三次
delete from store
where id=i;
#结束游标循环
end loop;
#关闭游标
close cur;
#输出结果
select total;
END
#创建接收游标数据的变量
declare i varchar(11);
declare n varchar(20);
declare c int;
#创建总数变量
declare total int default 0;
#创建结束标志变量
declare done int default false;
#创建游标
declare cur cursor for select id,name,count from store where name = 'iphone';
#指定游标循环结束时的返回值
declare continue HANDLER for not found set done = true;
#设置初始值
set total = 0;
#打开游标
open cur;
#开始循环游标里的数据
read_loop:loop
set total = total + 1;
#根据游标当前指向的一条数据
fetch cur into i,n,c;
#判断游标的循环是否结束
if done then
leave read_loop; #跳出游标循环
end if;
#获取一条数据时,将count值进行累加操作,这里可以做任意你想做的操作,
#set total = total + c;
##update store
## set count =i
## where id=i; #i只有三次,所以也只有三次
delete from store
where id=i;
#结束游标循环
end loop;
#关闭游标
close cur;
#输出结果
select total;
END