Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在存储过程中创建mysql嵌套循环_Mysql_Stored Procedures - Fatal编程技术网

如何在存储过程中创建mysql嵌套循环

如何在存储过程中创建mysql嵌套循环,mysql,stored-procedures,Mysql,Stored Procedures,我得到了要创建的异常。有人能帮我吗?如何以正确的方式在Mysql的存储过程中编写嵌套循环?我的错误是什么 DELIMITER $$ `INVESTMENT_MATCH_POINT_CREATOR`(_percentage INT, _vat_tex INT) BEGIN DECLARE _user_id INT; DECLARE _package_id INT; DECLARE _left_investment INT; DECLARE _right_in

我得到了要创建的异常。有人能帮我吗?如何以正确的方式在Mysql的存储过程中编写嵌套循环?我的错误是什么

DELIMITER $$

`INVESTMENT_MATCH_POINT_CREATOR`(_percentage INT, _vat_tex INT)
BEGIN
    DECLARE _user_id INT; 
    DECLARE _package_id INT;


    DECLARE _left_investment INT;
    DECLARE _right_investment INT;

    DECLARE _left_point INT;
    DECLARE _right_point INT;

    DECLARE _left_carry_point INT;
    DECLARE _right_carry_point INT;

    DECLARE _get_point INT;

    DECLARE done BOOLEAN DEFAULT FALSE;
    DECLARE _user_investment_table CURSOR FOR SELECT user_id,package_id,left_invesetment,right_investment DATA FROM user_investment_match;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

    OPEN _user_investment_table;

    read_loop:LOOP

    FETCH _user_investment_table INTO _user_id,_package_id,_left_investment,_right_investment;

    IF done THEN 
    LEAVE read_loop;
    END IF;

        BEGIN
                DECLARE _match_point INT; 
                DECLARE done2 BOOLEAN DEFAULT FALSE;

                DECLARE _package_match_point_table CURSOR FOR SELECT match_point DATA FROM package_match_points WHERE package_id=_package_id ORDER BY match_point DESC;
                DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = TRUE;

                OPEN _package_match_point_table;
                read_loop2:LOOP

                FETCH _package_match_point_table INTO _match_point;

                    IF done2 THEN 
                    LEAVE read_loop2;
                    END IF;

                    /*if(_match_point=<_left_investment) and (_match_point=<_right_investment) then
                        set _left_point=abs(_left_investment-_match_point);
                        set _right_point=abs(_right_investment-_match_point);
                        set _get_point=((_match_point*_percentage)/100);
                    end if;*/

                END LOOP;
                CLOSE _package_match_point_table;
            END$$




    END LOOP;
    CLOSE _user_investment_table;

END$$

DELIMITER ;

您应该只在过程的末尾使用指定的分隔符,但是在代码中,您是在内部块的末尾使用$$分隔符,换句话说,您正在使用$$分隔符,它在过程实际结束之前表示过程结束

您应该只在过程结束时使用指定的分隔符,但是在代码中,您在内部块的结尾使用$$分隔符,换句话说,您正在使用$$分隔符,它在过程实际结束之前表示过程结束

我敢打赌,99%的情况下,如果您嵌套了游标,那么您是做错了什么。你的示例代码太长了。我敢打赌,99%的情况下,如果你嵌套了游标,你就做错了。您的示例代码太长。