exception
  when others then
    if sqlcode = 08177 then
       result:=-201;
    elsif sqlcode = '00054 then
       result:=-101;
    else
       result:=-1;
    end if;
end;

解决方案 »

  1.   

    有一种写法,首先声明一个exception,定义到具体的号上面就行了,可是怎么写的忘了,我查查看
      

  2.   

    弱水兄,sqlcode好像返回的是负的 08177出来的结果如果没记错应该是-8177
      

  3.   

    哦,是这样了:create or replace ... as
      E1 exception ;
      PRAGMA EXCEPTION_INIT(E1, -60);
    begin
      ...
    exception 
      when E1 then
        ...
    end;
      

  4.   

    to  KingSunSha(弱水三千) ,你的做法好象不可以,异常处理中可以有“=”判断吗????
    to : xinpingf(白开心) ,你的办法可以,我看大家还有看法没有,我今天结帖
      

  5.   

    exception
     when substr(sqlerrm,1,9) = 'ORA-08177' then --好象是大写  
        result:=-201;
    --------------------------------------
    end;
      

  6.   

    sorry:exception when others then
     if substr(sqlerrm,1,9) = 'ORA-08177' then --好象是大写  
        result:=-201;
     else
       --------------------------------------
     end if;
    end;
      

  7.   

    回复人: bachelor(鹰飞九月) (  ) 信誉:100  2002-7-10 14:00:26  得分:0  
     
     
      to  KingSunSha(弱水三千) ,你的做法好象不可以,异常处理中可以有“=”判断吗????
    to : xinpingf(白开心) ,你的办法可以,我看大家还有看法没有,我今天结帖
      
     
    异常中可以使用“=”的,不但可以使用等号,还可以使用任何的pl/sql语句declare
       ....
    begin
      ...
    exception 
      when others then 
         begin
           ...
         exception 
            when ... then
               ...
         end ;
    end;这样都没有问题
      

  8.   

    我测试了一下,我的写法没有错啊,另外,SQLCODE返回的是正数。贴主为什么说不行啊?
      

  9.   

    我测试了一下,我的写法没有错啊,另外,SQLCODE返回的是正数。贴主为什么说不行啊?
      

  10.   

    KingSunSha(弱水三千) 是正确的.
      

  11.   

    我碰到了一个奇怪的现象:SQL> select * from a;        ID C
    ---------- -
             1SQL> declare
      2    n  number;
      3  begin
      4    select id into n from a where id >2;
      5  exception
      6    when others then
      7      dbms_output.put_line(sqlcode);
      8      dbms_output.put_line(sqlerrm);
      9  end;
     10  /
    100
    ORA-01403: 未找到数据PL/SQL 过程已成功完成。sqlcode = 100 ?? 这是怎么回事?
      

  12.   

    SQL> insert into a(id) values (1) ;已创建 1 行。SQL> commit;提交完成。
    SQL> ed
    已写入文件 afiedt.buf  1  declare
      2    n  number;
      3  begin
      4    select id into n from a where id =1;
      5  exception
      6    when others then
      7      dbms_output.put_line(sqlerrm);
      8      dbms_output.put_line(sqlcode);
      9* end;
    SQL> /
    ORA-01422: 实际返回的行数超出请求的行数
    -1422PL/SQL 过程已成功完成。
      

  13.   

    to KingSunSha(弱水三千):
    不好意思,我写成
    when sqlcode = 08177 then了,
    不好意思,你的方法是可以的
      

  14.   

    ORA-01403: 未找到数据系统定义的 no_data_found 类型sqlcode 在不同的环境中可能为100 或者 1403
      

  15.   

    第一次的情况可能有问题,sqlerrm和sqlcode出来的东西不一样不过第二次的结果是负的问题是,第一次是出了什么问题呢?
      

  16.   

    不可能啊,ora-00100应该是超出游标最大数的,不会那么巧吧,取sqlerrm时没问题,取sqlcode时就超出游标数了?
      

  17.   

    不可能啊,ora-00100应该是超出游标最大数的,不会那么巧吧,取sqlerrm时没问题,取sqlcode时就超出游标数了?
      

  18.   

    ora-00100就是no data found