以scott用户登陆
SQL> create or replace function isExist(eid number) return boolean
  2  as
  3  c number;
  4  begin
  5  select count(*) into c from emp where empno=eid;
  6    if c=1 then
  7       return true;
  8    else
  9       return false;
 10    end if;
 11  exception
 12      when value_error then
 13   DBMS_output.put_line('输入有误');
 14  end;
 15  /
 
Function created
 
SQL> 
SQL> create or replace  procedure updateEmpSal(eid number)
  2  is
  3  begin
  4  if (isExist(eid)) then
  5     update emp set sal=sal+1000 where empno=eid;
  6  else
  7     dbms_output.put_line('没找到');
  8  end if;
  9  exception
 10      when value_error then
 11   DBMS_output.put_line('输入有误');
 12  end;
 13  /
Procedure created当执行execute updateEmpSal('sdsd');时应该输出:输入有误,但为什么输出的确实
ORA-06502: PL/SQL: 数字或值错误 :  字符到数值的转换错误
ORA-06512: 在line 2

解决方案 »

  1.   

    create or replace procedure updateEmpSal(eid number)
                                           ============== 
    execute   updateEmpSal('sdsd');
                          =========oracle 在做语法检查时,不能将参数 'sdsd' 转换成 number 类型,还未执行过程主体就出错了。
      

  2.   

    对唉...我不是
              exception 
      10             when   value_error   then 
      11     DBMS_output.put_line('输入有误');
    捕获异常了嘛????? ...为什么DBMS_output.put_line('输入有误');没执行
      

  3.   

    在你调用存储过程的时候还没有进入到你捕获异常的begin end块里面呢,怎么能够捕获异常啊?
    调用语句输入的参数就是错误的。
      

  4.   

    create or replace function isExist(number eid ) return boolean as
      c number;
    begin
      select count(*) into c from emp where empno = eid;
      if c = 1 then
        return true;
      else
        return false;
      end if;
    exception
      when value_error then
        DBMS_output.put_line('输入有误');
    end;
    create or replace procedure updateEmpSal(number eid) is
    begin
      if (isExist(eid)) then
        update emp set sal = sal + 1000 where empno = eid;
      else
        dbms_output.put_line('没找到');
      end if;
    exception
      when value_error then
        DBMS_output.put_line('输入有误');
    end;
    execute   updateEmpSal(数字);