200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > MYSQL存储过程开发中如何使用游标嵌套【MySQL】

MYSQL存储过程开发中如何使用游标嵌套【MySQL】

时间:2019-10-03 04:50:56

相关推荐

MYSQL存储过程开发中如何使用游标嵌套【MySQL】

数据库|mysql教程

游标,开发,如何

数据库-mysql教程

MYSQL存储过程开发中如何使用游标嵌套 在实际业务逻辑开发中,难免用到游标嵌套,举例如下: delimiter //drop procedure if exists good_nested_cursors1//CREATE PROCEDURE good_nested_cursors1( ) READS SQL DATABEGIN DECLARE l_grade_id INT; DECLARE l_class_id INT; DECLARE l_class_cntINT DEFAULT 0 ; DECLARE l_doneINT DEFAULT 0;DECLARE grade_csr cursor FOR SELECT grade_id FROM org_grade; DECLARE class_csr cursor FORSELECT class_id FROM org_class WHERE grade_id=l_grade_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_done=1; OPEN grade_csr; grade_loop: LOOP — Loop through org_grade FETCH grade_csr into l_grade_id;select concat(‘年级:’, l_grade_id); IF l_done=1 THEN LEAVE grade_loop; END IF;OPEN class_csr; SET l_class_cnt=0; class_loop: LOOP— Loop through class in grade.FETCH class_csr INTO l_class_id; IF l_done=1 THEN LEAVE class_loop;END IF;SET l_class_cnt=l_class_cnt+1;select concat(‘ 班级:’, l_class_id); END LOOP; CLOSE class_csr; SET l_done=0;END LOOP grade_loop; CLOSE grade_csr; END;// delimiter ; /////////////////////////////////////////////////////////另一个例子:CREATE PROCEDURE curdemo() NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER COMMENT ” BEGIN declare done1,done2 int default 0; declare name1,name2 varchar(20); declare id1,id2 int; declare cur1 cursor for select id,name from test1; declare continue handler for not found set done1 = 1; open cur1; repeat fetch cur1 into id1, name1; if not done1 then insert into test3(name) values(name1); begin declare cur2 cursor for select id,name from test2; declare continue handler for not found set done2 = 1; open cur2; repeat fetch cur2 into id2,name2; if not done2 then insert into test3(name) values(name2); end if;until done2 end repeat; close cur2; set done2=0; end; end if; until done1 end repeat; close cur1; commit; END; /// 作者 蔡磊

墓地源码,vscode使用type=,ubuntu删除其他系统,tomcat由来,电脑编辑sqlite,dedecms怎么上传到服务器,支付宝密码显示无法加载插件,fe中文前端框架,怎么去除房间爬虫,php微云,网站免费seo教程,视频种子分享网站源码,html5网页模板代码,收费网站模板,页面冒泡提示,实验课程管理系统,35. 计算机源程序是lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。