各位老师,我现在遇到一个问题,想用continue实现,可是PL/SQL并不支持,现有如下代码:
    loop
       begin      
            fetch Tmp_Cur into xwconfig_Row;
            exit when Tmp_Cur%notfound;
            insert into tr_xwconfig values(xwconfig_Row.EXCODE,     
                                           '20'||xwconfig_Row.SEATNO,     
                                           xwconfig_Row.BROKERNO,   
                                           xwconfig_Row.SEATTYPE,   
                                           xwconfig_Row.STARTCONTNO,
                                           xwconfig_Row.ENDCONTNO,  
                                           xwconfig_Row.CONTINUEBZ, 
                                           xwconfig_Row.PRECONTNO,  
                                           xwconfig_Row.BDEFAULT,   
                                           xwconfig_Row.BNOWTCJ    
                                           );
        exception--如果发现已经处理了,继续处理下一条
            when others then
                 null; --continue;    
        end;
    end loop;
我想在发生异常时,继续下一次循环,可是现在没有办法实现,我想用goto但是也不行,如下:
    loop
       begin      
            <<lable1>>
            fetch Tmp_Cur into xwconfig_Row;
            exit when Tmp_Cur%notfound;
            insert into tr_xwconfig values(xwconfig_Row.EXCODE,     
                                           '20'||xwconfig_Row.SEATNO,     
                                           xwconfig_Row.BROKERNO,   
                                           xwconfig_Row.SEATTYPE,   
                                           xwconfig_Row.STARTCONTNO,
                                           xwconfig_Row.ENDCONTNO,  
                                           xwconfig_Row.CONTINUEBZ, 
                                           xwconfig_Row.PRECONTNO,  
                                           xwconfig_Row.BDEFAULT,   
                                           xwconfig_Row.BNOWTCJ    
                                           );
        exception--如果发现已经处理了,继续处理下一条
            when others then
                 goto lable1;  
        end;
    end loop;
这样写的话编译都通不过,不知道怎么处理了现在,请大家帮忙。
请大家注意的是,insert之前不能删除那条记录以避免异常的发生

解决方案 »

  1.   

    loop
           begin      
                fetch Tmp_Cur into xwconfig_Row;
                exit when Tmp_Cur%notfound;
                insert into tr_xwconfig values(xwconfig_Row.EXCODE,     
                                               '20'||xwconfig_Row.SEATNO,     
                                               xwconfig_Row.BROKERNO,   
                                               xwconfig_Row.SEATTYPE,   
                                               xwconfig_Row.STARTCONTNO,
                                               xwconfig_Row.ENDCONTNO,  
                                               xwconfig_Row.CONTINUEBZ, 
                                               xwconfig_Row.PRECONTNO,  
                                               xwconfig_Row.BDEFAULT,   
                                               xwconfig_Row.BNOWTCJ    
                                               );
            exception--如果发现已经处理了,继续处理下一条
                when others then
                null;  
            end;
        end loop;不用label,出现异常后将其截获,然后什么也不做,null,这样它自动走下一次循环,当然,null这种什么也不做的行为不值得推荐,建议你可以输出到类似日志一类的东西,方便自己发现错误。
      

  2.   

    改成这样应该可以:
        loop
                 
           fetch Tmp_Cur into xwconfig_Row;
           exit when Tmp_Cur%notfound;
           begin
                insert into tr_xwconfig values(xwconfig_Row.EXCODE,     
                                               '20'||xwconfig_Row.SEATNO,     
                                               xwconfig_Row.BROKERNO,   
                                               xwconfig_Row.SEATTYPE,   
                                               xwconfig_Row.STARTCONTNO,
                                               xwconfig_Row.ENDCONTNO,  
                                               xwconfig_Row.CONTINUEBZ, 
                                               xwconfig_Row.PRECONTNO,  
                                               xwconfig_Row.BDEFAULT,   
                                               xwconfig_Row.BNOWTCJ    
                                               );
            exception--如果发现已经处理了,继续处理下一条
                when others then
                     null; --continue;    
            end;
        end loop;