【CCID-IT技术报告】本文介绍了一个MySQL存储过程mysql存储过程 循环mysql存储过程 循环,其中涉及到使用,示例如下:
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 select 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 set stopFlag=1; OPEN cursor_name; REPEAT FETCH cursor_name INTO p_group_id,p_num; begin update t_groupinfo set c_member_number=p_num where c_group_id=p_group_id; end; UNTIL stopFlag = 1 END REPEAT; CLOSE cursor_name; END;
总结:1、注意设置游标:FOR NOT FOUND set =1;2、注意使用UTILE[停止条件]END,否则不会循环; 3、如何RUN、进入、执行:call()
文章来源:http://www.ccidnet.com/2009/0305/1697795.shtml
感谢您的来访,获取更多精彩文章请收藏本站。
© 版权声明
THE END