OPEN cur;
REPEAT
FETCH cur INTO int_type, int_element_id, int_num, int_user_id;
IF NOT _DONE THEN
IF int_type = THEN SET int_num_raw = ; SELECT num INTO int_num_raw FROM user_item WHERE user_id = int_user_id AND item_id = int_element_id;
SET _DONE = 0;
IF int_num_raw < int_item_max_overlap THEN
IF int_num_raw + int_num > int_item_max_overlap THEN
SET int_num = int_item_max_overlap - int_num_raw;
END IF;
INSERT INTO user_item SET user_id = int_user_id, item_id = int_element_id, num = int_num ON DUPLICATE KEY UPDATE num = num + int_num;
END IF; ELSEIF int_type = THEN
UPDATE `user` SET `exp` = `exp` + int_num WHERE `user_id` = int_user_id;
ELSEIF int_type = THEN
UPDATE `user` SET `gold` = `gold` + int_num WHERE `user_id` = int_user_id;
ELSEIF int_type = THEN
UPDATE `user` SET `diamond` = `diamond` + int_num WHERE `user_id` = int_user_id;
ELSEIF int_type = THEN
UPDATE `user` SET `health_cur` = `health_cur` + int_num WHERE `user_id` = int_user_id;
END IF;
END IF;
UNTIL _DONE END REPEAT;
CLOSE cur;
加红的需要注意,需要设置set _done = 0,否则循环无法进行下去,坑了我半天。。。