mysql 存储过程中注意的问题

        OPEN cur;
        REPEAT
            FETCH cur INTO int_type, int_element_id, int_num, int_user_id;
            IF NOT _DONE THEN
                IF int_type = 8 THEN 

                    SET int_num_raw = 0;

                    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 = 11 THEN 
                    UPDATE `user` SET `exp` = `exp` + int_num WHERE `user_id` = int_user_id;
                ELSEIF int_type = 12 THEN 
                    UPDATE `user` SET `gold` = `gold` + int_num WHERE `user_id` = int_user_id;
                ELSEIF int_type = 13 THEN 
                    UPDATE `user` SET `diamond` = `diamond` + int_num WHERE `user_id` = int_user_id;
                ELSEIF int_type = 14 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,否则循环无法进行下去,坑了我半天。。。

posted @ 2015-07-10 15:43  zzyoucan  阅读(403)  评论(0编辑  收藏  举报