mysql中declare语句⽤法_mysqldeclare怎么⽤Q4:mysql declare cursor只能放在前⾯吗
冬天养花
本⽂中介绍了⼀个MySQL的存储过程,其中涉及Cursor的使⽤
⽰例如下:
复制代码
代码如下:
CREATE PROCEDURE `justifyGroupNum`()
NOT DETERMINISTIC
SQL SECURITY DEFINER
外臣
COMMENT
妈妈的英文怎么读BEGIN
/*how to run:call justifyGroupNum()*/
深圳龙城广场
DECLARE p_group_id int;
declare p_num int;
declare stopFlag int;
DECLARE cursor_name CURSOR
FOR lect c_group_id,count(*) as num
from `t_group_member`
where
c_valid in (3,4)
group by c_group_id;
DECLARE CONTINUE HANDLER FOR NOT
FOUND t stopFlag=1;
OPEN cursor_name;城西农贸市场
REPEAT
FETCH cursor_name
INTO p_group_id,p_num;
begin
update t_groupinfo t
c_member_number=p_num where c_group_id=p_group_id;
end;
UNTIL stopFlag =
88什么意思1
END REPEAT;
观赏
CLOSE cursor_name;
END;
总结:
1、注意设置游标的countinue handler:DECLARE CONTINUE HANDLER FOR NOT FOUND t stopFlag=1;
2、注意REPEAT和UTILE [停⽌条件] END REPEAT的使⽤,否则不会循环;
3、如何RUN,输⼊并执⾏:call justifyGroupNum()土豆的家常做法
WWw.yIjITao.CO.m