本人有这么个疑惑:我认为oracle中发生的错误就一个异常,比如:插入一条语句失败、更新一条语句失败、没有查询出结果,这都是异常。异常可以这么认为吗?
我下面的程序片段:es_sort表中只有三个字段,我插入了四个,为什么没有抛出一个异常,即打印id错误dbms_output.put_line('id错误');而是一直弹出一个窗口:告诉我值过多。这是这个表结构
create table ES_SORT
(
  ID       NUMBER(10) not null,
  SORTNAME VARCHAR2(40) not null,
  FATHERID NUMBER(10)
)这个是执行的PL/SQL块
begin
 insert into es_sort values(19,'电脑12',9,‘ooo’);
 insert into es_sort values(13,'电脑13',9);
 commit;
 exception
    when others then 
      dbms_output.put_line('id错误');
 rollback;
end;

解决方案 »

  1.   

    我一般这样做异常处理
    exception
      when others then  
    begin
      dbms_output.put_line('id错误');
     rollback;
    raise;
    end;
      

  2.   

    写好一个存储过程 1.编译 2.执行
    你的错误是Oracle编译都没有通过,就像写一个java类 int a = 'abc'; 这样的语句本身就不会通过编译的一样。
      

  3.   

    begin
     insert into es_sort values(19,'电脑12',9,‘ooo’);--这句编译时就报错,不会执行
     insert into es_sort values(13,'电脑13',9);
     commit;
     exception
      when others then --执行时才有可能走到这里
      dbms_output.put_line('id错误');
     rollback;
    end;