MySql过程GOTO语句

时间:2015-05-19 07:35:41

标签: mysql

我想在Mysql存储过程中使用goto语句,以便在条件再次变为true时执行我的游标。

这只是一个示例代码,我只是在寻找goto语句

BLOCK_BACKLOG:begin
    declare backlgId, oldCOR, oldATR,oldCourse,oldATR,isFormFilled,nextParentId int;
    declare backlogNoMoreRow boolean default false;

Label : TestLineStart
    declare backlogCur cursor for select bcklg.id,cor.id,atr.id,cr.id,atr.obtainedMarks,atr.isFormFilled,atr.parentRegistration_id 
                from train bcklg,bus cor,fliet atr,fair co,distance cr 
                where bcklg.courseofferingregistration_id=cor.id and cor.academictermregistration_id=atr.id and cor.courseoffering_id=co.id and co.course_id=cr.id
                and bcklg.isDeleted is false and atr.id=parentId;
    declare continue handler for not found set backlogNoMoreRow=true;

    open backlogCur;

    LOOP_BACKLOG: loop
        fetch backlogCur into backlgId, oldCOR, oldATR,oldCourse,oldATRMarks,isFormFilled,nextParentId;                             

        if backlogNoMoreRow then
                close backlogCur;
                leave LOOP_BACKLOG;
        end if;

           if isFormFilled==0 then
        parentId=nextParentId;
        GOTO TestLineStart;
        end if;

1 个答案:

答案 0 :(得分:1)

您可以根据变量LOOP的值在外部区块上使用isFormFilled

以下更改可能会对您有所帮助。

-- Label : TestLineStart
TestLineStart: LOOP
-- other part of your SP as it is

并进行以下更改:

if isFormFilled==0 then
    parentId=nextParentId;
    -- GOTO TestLineStart;
else
    leave TestLineStart;
end if;

您必须正确关闭所有loop语句。