比如遍历游标循环中,游标总共有11条记录,遍历到第8个,报错了,这个时候如何继续忽略掉这个错误,继续遍历第9个第10个第11个呢?样例如下:
create or replace procedure c1
is 
       cursor c1 is select cid,.... from tb where .....;
begin
       open c1
       loop c1 into v_id,......         
            update tb1 set column1=v_c1,...... where id=v_id ......
                       
       exception 
           when others then
                  --遍历到第8个报错,到了这里,异常如何处理,v_id为主键id,我想继续回到前面的游标遍历逻辑中,继续遍历第9个第10个第11个。
   end loop;  
commit;                        
end

解决方案 »

  1.   

    可以的。loop begin
    -- 这里写上你的处理内容
    exception 
    when others then ...
    endend loop 
      

  2.   

    begin
           open c1
           loop c1 into v_id,......         
                begin   -- 这里加一个  begin 
                update tb1 set column1=v_c1,...... where id=v_id ......
                           
           exception 
               when others then
                         null ;    --- 这里可以写一个 null ,代表什么都不做,也可以写你的业务逻辑
                      --遍历到第8个报错,到了这里,异常如何处理,v_id为主键id,我想继续回到前面的游标遍历逻辑中,继续遍历第9个第10个第11个。
             end ;  -- 这里来一个 end , 这样一来,9 出错, 10 和 11 还可以接着跑,不出错。
       end loop;  
    commit;                        
    end
      

  3.   

    可以试试用continue,或者用版主说的使用嵌套匿名块(begin....end)来控制代码不结束