欢迎来到LYBLaoInB的博客
LYBLaoInB
LYBLaoInB
回首往事,不因虚度年华而悔恨,不因碌碌无为而愧疚

存储过程中的游标cursor

存储过程里的游标,其实就是结果集,然后想操作结果集中的数据,一行行读取游标即可

首先要声明一个游标

delimiter $$
CREATE procedure changeName()
begin
declare stopflag int default 0;
declare myname varchar(20) default '';
declare my_cursor cursor for select sname from student where sid%2=0;
declare continue handler for not found set stopflag=1;
open my_cursor;
while(stopflag=0) do
begin
fetch my_cursor into myname;
update student set sname = concat(sname,'aab') where sname = myname;
end;
end while;
close my_cursor;
end;
$$

以上是对游标的一个使用,

注意点:

游标的声明需要在所有其他变量之后,游标常常要配合一个状态值来实现功能,需要声明一个休止标识

declare continue handler for not found set 休止标识=1;

游标使用要先open,最后需要close

游标值的获取用fetch my_cursor into 某变量

 

posted @ 2019-06-11 15:51  LiuYongbo  阅读(3667)  评论(0编辑  收藏  举报
<--将网易云歌单中的id复制到上面的data-id中就可以了 http://music.163.com/playlist?id=3103841025&userid=1698529278 -->