当前位置: 数据库>mysql
MySql游标的使用实例
来源: 互联网 发布时间:2014-10-15
本文导语: mysql游标使用的整个过程为: 1.创建游标 代码如下:DECLARE calc_bonus CURSOR FOR SELECT id, salary, commission FROM employees; 2.打开游标 代码如下:OPEN calc_bonus; 3.使用游标 代码如下:FETCH calc_bonus INTO re_id, re_salary, re_comm; 4.关闭游标 代码如下:CLOSE...
mysql游标使用的整个过程为:
1.创建游标
代码如下:
DECLARE calc_bonus CURSOR FOR SELECT id, salary, commission FROM employees;
2.打开游标
代码如下:
OPEN calc_bonus;
3.使用游标
代码如下:
FETCH calc_bonus INTO re_id, re_salary, re_comm;
4.关闭游标
代码如下:
CLOSE calc_bonus;
实例代码如下所示:
代码如下:
begin
declare temp_user_id int default null;
declare stop int default 0;
#声明游标
declare temp_cur cursor for select f_user_id from table_test where f_user_id=1;
#声明游标的异常处理
declare continue handler for sqlstate '02000' set stop=1;
open temp_cur;
fetch temp_cur into temp_user_id;
#判断游标是否到达最后
while stop1 do
#各种判断
#读取下一行的数据
fetch temp_cur into temp_user_id;
#循环结束
end while;
#关闭游标
close temp_cur;
end
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。