对于MySQL,它是专用的。
我最近做了点什么,写了一个MySQL存储过程。 其中包括使用Cursor,如下所示。
创建进程` justifygroupnum ` (
非细节
SQL SECURITY DEFINER
COMMENT ' '
比根
/* how torun : calljustifygroupnum () ) /
DECLARE p_group_id int;
declare p_num int;
取消停止标志int;
DECLARE cursor_name CURSOR
FOR select c_group_id,count(* ) as num
from `t_group_member `
wherec _ validin (3,4 ) ) ) ) ) ) ) ) wherec _ validin (3,4 ) ) ) ) ) wherec _ validin (3,4 ) ) ) ) ) ) ) ) ) wher ) ) wher )。
group by c_group_id;
declarecontinuehandlerfornotfoundsetstopflag=1;
OPEN cursor_name;
REPEAT
FETCH cursor_name INTO p_group_id,p_num;
比根
updatet _ group infos etc _ member _ number=p _ numwherec _ group _ id=p _ group _ id;
结束;
UNTIL stopFlag=1
结束报告;
CLOSE cursor_name;
结束;
关注点如下。
1、注意光标countinuehandler的设置: declarecontinuehandlerfornotfoundsetstopflag=1;
2、请注意使用REPEAT和UTILE [停止条件] END REPEAT。 不这样做的话就不会循环;
3、如何运行? 输入并运行: call justifyGroupNum (