您的位置:首页 > 数据库

MSQL存储过程

2016-06-08 19:13 246 查看
BEGIN

declare _userName varchar(12); -- 用户名

declare _chinese int ; -- 语文

declare _math int ;    -- 数学

declare done int;

-- 定义游标

DECLARE rs_cursor CURSOR FOR SELECT username,chinese,math from userInfo where datediff(createDate, date_day)=0;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;

-- 获取昨天的日期

if date_day is null then

   set date_day = date_add(now(),interval -1 day);

end if;

open rs_cursor;

cursor_loop:loop

   FETCH rs_cursor into _userName, _chinese, _math; -- 取数据

   if done=1 then

    leave cursor_loop;

   end if;

   -- 更新表

   update infoSum set total=_chinese+_math where UserName=_userName;

end loop cursor_loop;

close rs_cursor;

    END
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  myeclipse math