首页 > 编程知识 正文

数据库存储过程写法,Mysql存储过程

时间:2023-05-04 08:58:42 阅读:168190 作者:2929

对于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 (

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。