Examples are as follows:
Copy Code code as follows:
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;
Summarize:
1. Note Set cursor countinue Handler:declare CONTINUE handler for not FOUND set stopflag=1;
2, pay attention to repeat and utile [stop condition] end repeat use, otherwise will not cycle;
3. How to run, enter and execute: Call Justifygroupnum ()