码迷,mamicode.com
首页 > 数据库 > 详细

MySql 游标

时间:2016-12-02 01:11:37      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:cal   var   etc   efault   最大   set   for   mysql   next   

create procedure delWord_activety()
BEGIN
DECLARE Done INT DEFAULT 0;
DECLARE v_id VARCHAR(50);
DECLARE v_content text;
DECLARE f_content text;

/*声明游标*/
DECLARE rs CURSOR FOR SELECT id,content FROM cms_activity_data_121;
/*异常处理*/
DECLARE CONTINUE HANDLER FOR SQLSTATE ‘02000‘ SET Done=1;
/*打开游标*/
OPEN rs;
/*逐个取出当前记录LingQi字段的值,需要进行最大值的判断*/
FETCH NEXT FROM rs INTO v_id,v_content;
/*遍历数据表*/
REPEAT
IF NOT Done THEN

set v_content=replace(v_content,char(10),‘‘);
set v_content=replace(v_content,char(13),‘‘);

update cms_activity_data set content=v_content where id=v_id;

END IF;
FETCH NEXT FROM rs INTO v_id,v_content;

UNTIL Done END REPEAT;
/*关闭游标*/
CLOSE rs;
end

DROP PROCEDURE delWord_activety
call delWord_activety()

MySql 游标

标签:cal   var   etc   efault   最大   set   for   mysql   next   

原文地址:http://www.cnblogs.com/leonkobe/p/6123753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!