逐条插入的时候可以通过定义内部块和异常处理,使其他记录能继续插入 请问下这个内部块和异常处理 是怎么操作的?

解决方案 »

  1.   

    SQL> 
    SQL> create table test (id number);Table createdSQL> alter table test add constraint pk_id primary key (id);Table alteredSQL> insert into test values(1);1 row insertedSQL> insert into test values(1);insert into test values(1)ORA-00001: 违反唯一约束条件 (MMSRPT1.PK_ID)SQL> declare
      2      error_primary exception;
      3      pragma exception_init(error_primary, -1);
      4  
      5      v_tabname         varchar(30);
      6      v_sqlstring       varchar(1024);
      7  begin
      8      begin
      9          insert into test values(1);
     10      exception
     11          when error_primary then
     12              null;
     13      end;
     14  
     15      insert into test values(2);
     16      commit;
     17  exception
     18      when others then
     19          dbms_output.put_line(substr(sqlerrm, 1, 200));
     20  end;
     21  /PL/SQL procedure successfully completedSQL> select * from test;        ID
    ----------
             1
             2SQL>