CREATEPROCEDUREupdate_pointer()begin/*done为1执行异常,停止执行*/DECLAREDoneINTDEFAULT0;DECLAREnowtimeINT;DECLAREyuefloat;DECLAREuidint;DECLAREyqmoneyfloat;DECLAREsummone...
CREATE PROCEDURE update_pointer()begin/*done为1执行异常,停止执行*/DECLARE Done INT DEFAULT 0;DECLARE nowtime INT;DECLARE yue float;DECLARE uid int;DECLARE yqmoney float;DECLARE summoney float;DECLARE overtime INT;DECLARE hyue float;/*SET nowtime=current_time();*//* 声明游标 */DECLARE rs CURSOR FOR SELECT id,money,username,htime,overduetime FROM zhangdan WHERE paystatus!=1;/* 异常处理 */DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET Done = 1;/* 打开游标 */OPEN rs;FETCH NEXT FROM rs INTO nowtime,yue,uid,yqmoney,summoney,overtime,hyue;/* 遍历数据表 */REPEATIF NOT DoneTHENSET nowtime=current_time();IF nowtime >= htimeTHENSELECT money into yue FROM pmw_member where pmw_member.username=username;SELECT id into uid FROM pmw_member where pmw_member.username=username;SET yqmoney = convert((ceil(overduetime/(24*60*60))*0.01),2);SET summoney = money + yqmoney;IF yue < summoneyTHENSET overtime = nowtime-htime;UPDATE zhangdan SET overduetime = overtime WHERE zhangdan.id = id;ELSESET hyue = yue-summoney;UPDATE pmw_member SET pmw_member.money = hyue WHERE pmw_member.username = username;UPDATE zhangdan SET paystatus = 1 WHERE zhangdan.id = id;INSERT INTO `pmw_money` (`username`, `uid`, `title`, `money`, `leixing`, `posttime`, `pid`, `hkjzrq`, `yqlx`, `payorderid`) VALUES ('username', 'uid', '还款', 'money', '支出', 'nowtime', 'pid','htime','yqmoney','goodsorderid');END IF;END IF;END IF;FETCH NEXT FROM rs INTO nowtime,yue,uid,yqmoney,summoney,overtime,hyue;UNTIL Done END REPEAT;/* 关闭游标 */CLOSE rs;end
展开