如下代码来自 http://www.iteye.com/topic/1026084
1.drop procedure if exists `sp_nested_cursor`;
2.create procedure `sp_nested_cursor`()
3.begin
4. declare v_uid bigint(22);
5. declare v_code varchar(100);
6. declare v_value varchar(100);
7. declare _done TINYINT(1) default 0;
8. declare cur_user cursor for select id from `tb_user`;
9. declare continue handler for not found set _done = 1;
10.
11. open cur_user;
12. loop_xxx:loop
13. fetch cur_user into v_uid;
14. if _done=1 then
15. leave loop_xxx;
16. end if;
17. begin
18. declare _inner tinyint(1) default 0;
19. declare cur_param cursor for select code, value
20. from `tb_user_param`
21. where user_id=v_uid;
22. declare continue handler for not found set _inner = 1;
23. open cur_param;
24. loop_yyy:loop
25. fetch cur_param into v_code, v_value;
26. if _inner=1 then
27. leave loop_yyy;
28. end if;
29. insert into tb_key_value values (v_uid, v_code, v_value);
30. end loop;
31. commit;
32. end;
33. end loop;
34.end;
在sqlyog enterprise工具中执行
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'loop_yyy:loop
fetch cur_param into v_code, v_value' at line 1
(0 ms taken)
mysql5.0 不支持这种写法?
相关推荐
Mysql游标(循环操作)
mysql游标嵌套[文].pdf
一个存储过程的示例,简单展示了如下方面: ...4,对于嵌套游标STATUS的互相影响问题的解决办法《注意001和002的注释位置,fetch的位置》。 对于初学者,存储过程重要的几个方面,都有展示到,大虾们请忽略。
SQL对游标嵌套的应用 学校宿舍管理系统(实际上是个子系统): 包括以下几个表: 楼栋表;楼层表;房间表;学员住宿表 脚本如下: --楼栋表
NULL 博文链接:https://modiliany.iteye.com/blog/786230
MySql存储过程,游标的使用方法,速度极快!
matlab开发-图窗口的数据游标。fugure中多轴数据光标支持
本节主要介绍了Mysql存储过程循环内如何嵌套使用游标,详细实现如下,需要的朋友不要错过
Oracle Package有简化应用设计、提高应用性能、实现信息隐藏、子程序重载作用。本文举例说明了Oracle Package中返回游标的写法和调用。
mysql游标使用的整个过程为: 1.创建游标 代码如下:DECLARE calc_bonus CURSOR FOR SELECT id, salary, commission FROM employees; 2.打开游标 代码如下:OPEN calc_bonus; 3.使用游标 代码如下:FETCH calc_bonus ...
游标的作用,游标的写法,游标的注意事项,SQLAERVER游标
带游标的mysql存储过程例子。
Mysql存储过程游标触发器
mysql动态游标示例,通过准备语句、视图和静态游标实现,大家参考使用吧
Mysql从5.0开始支持存储过程和trigger,游标在递归树结构中非常好用
mysql声明游标的方法: 1、声明变量和游标 declare result varchar(3000); declare flag1 varchar(100); DECLARE done INT DEFAULT FALSE; declare cur1 CURSOR FOR SELECT flag from bmlx; 2、变量赋值 DECLARE ...
NULL 博文链接:https://fangyong2006.iteye.com/blog/768291
[mysql游标的用法及作用] 例子: 当前有三张表A、B、C其中A和B是一对多关系,B和C是一对多关系,现在需要将B中A表的主键存到C中; 常规思路就是将B中查询出来然后通过一个update语句来更新C表就可以了,但是B表中有...