记录下常用的mysql存储过程修改数据游标集
常见的就是select一大堆结果集合,然后存储过程更新某些字段,很常见,
BEGIN DECLARE IDS int; DECLARE permitstatus_s int; DECLARE b INT DEFAULT 0; DECLARE done INT DEFAULT 0; DECLARE cur_1 CURSOR FOR (SELECT t_asset_log_detail.ID as IDS FROM t_asset_log, t_asset_log_detail WHERE t_asset_log.ID = t_asset_log_detail.ASSET_LOG_ID AND (permitstatus = 0 or permitstatus is null) AND t_asset_log.OP_TYPE = 1); DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; OPEN cur_1; REPEAT FETCH cur_1 INTO IDS; /*获取第一条记录*/ IF NOT done THEN SELECT concat('myvar is ', IDS); update t_asset_log_detail set permitstatus=4 where ID=IDS; COMMIT; END IF; UNTIL done END REPEAT; CLOSE cur_1; end
欢迎大家阅读《记录下惯用的MYSQL存储过程修改数据游标集_mysql》,跪求各位点评,by 搞代码
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~