mysql 游标中可以嵌套游标吗

 我来答
匿名用户
推荐于2016-04-16
展开全部
CREATE PROCEDURE SumOfStu(OUT Sdeptno int,OUT Sdeptname char(20),OUT sumBefore int,OUT sumAfter int)
BEGIN
DECLARE l_sum int;
DECLARE l_Sdeptno int;
DECLARE l_sno int;
DECLARE l_sumBefore int;
DECLARE done, done2 INT DEFAULT 0;
DECLARE cur_out cursor for select SdeptNo,population from Department;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur_out;
REPEAT
SET l_sum=0;
FETCH cur_out INTO l_Sdeptno,l_sumBefore;
IF NOT done THEN
BEGIN
DECLARE cur_inner cursor for select Sno from student where SdeptNo=l_Sdeptno;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = 1;
OPEN cur_inner;
REPEAT
FETCH cur_inner into l_sno;
IF NOT done2 THEN
SET ps_count = 0;
SET l_sum=l_sum+1;
END IF;
UNTIL done2
END REPEAT;
CLOSE cur_inner;
SET done2 = 0;
END;
IF(l_sum<>l_sumBefore) THEN
update department SET population=l_sum where SdeptNo=l_Sdeptno;
select l_Sdeptno INTO Sdeptno;
select SdeptName INTO Sdeptname from Department where SdeptNo=l_Sdeptno;
select l_sumBefore INTO sumBefore;
select l_sum INTO sumAfter;
end IF;
END IF;
UNTIL done
END REPEAT;
CLOSE cur_out;
END
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式