出发异常后  要在异常里面执行什么么?执行update前  做个判断不行么?

解决方案 »

  1.   


    create or replace procedure pro_update_idcard
    as
    --这只是一个测试用例,实际程序有很多语句,但就是想有异常也能继续往下执行后面没错的语句。
    begin
      for i in(select * from yjf_dongcheng)
      loop  
        --语句1:此语句触发主见约束异常,表中有为2的.
        begin
         update yjf_dongcheng t set t.anv04yjfid='1' where t.anv04yjfid='2';  
        exception
          when others then
          --语句2:想让下面这条语句继续执行
           update yjf_dongcheng t set t.anv04yjfid='1' where t.anv04yjfid='2a';
        end;
      
        commit;
        --最终第二条语句提交。
      end loop;end;
      

  2.   

    BEGIN
        ...............
        --使用begin..exception..end块
        BEGIN
          UPDATE yjf_dongcheng t
             SET t.anv04yjfid = '1'
           WHERE t.anv04yjfid = '2';
        EXCEPTION
          WHEN OTHERS THEN
            NULL;--不处理异常
        END;
        --继续执行其它语句
        .................
    END;
      

  3.   

    create or replace procedure pro_update_idcard as
    begin
      for i in (select * from yjf_dongcheng) 
      loop
        begin 
        update yjf_dongcheng t set t.anv04yjfid = '1' where t.anv04yjfid = '2';
      exception
        when others then
           update yjf_dongcheng t set t.anv04yjfid = '1' where t.anv04yjfid = '2a';
           end;
       commit;
    end loop;
    end;