begin 
insert into tbname ...values ...;
exception when others then
   ...
end;

解决方案 »

  1.   

    example:
    create or replace procedure tes as
    sqlc integer;
    begin
      insert into t1 values (1);
      sqlc:=sqlcode;
      if sqlc=0 then
        dbms_output.put_line('成功!');
      else
        dbms_output.put_line('失败!');
      end if;
    end;
    /
      

  2.   

    使用sql%rowcount得到dml语句处理记录的条数.[code]
      1  declare
      2     v_count int;
      3  begin
      4     execute immediate 'delete from t where rownum < 10';
      5     v_count := sql%rowcount;
      6     dbms_output.put_line('deleted '||v_count||' rows ');
      7     execute immediate 'update t set created = sysdate where rownum < 10';
      8     v_count := sql%rowcount;
      9     dbms_output.put_line('updated '||v_count||' rows ');
     10* end;
    14:03:16 SQL> /
    deleted 9 rows
    updated 9 rowsPL/SQL procedure successfully completed.Elapsed: 00:00:00.01
    14:03:16 SQL>
    [/code]
      

  3.   

    同意bzszp(SongZip)的做法!
    zmgowin(隐者(龙祖宗)) 的也不错!
      

  4.   

    bzszp(SongZip)和zmgowin(隐者(龙祖宗)) 的做法效率比较好,三楼的记录太多的时候效率比较差
      

  5.   

    bzszp(SongZip)和zmgowin(隐者(龙祖宗)) 对insert语句当然比较不错。
    但是update不太一样,还是用sql%rowcount或sql%notfound之类的比较好。