如何处理输入参数的过程中的异常

时间:2017-01-05 11:36:08

标签: oracle11g exception-handling procedure

我想要输入参数的陷阱异常:

create or replace procedure 
    dept_employee_info (P_deptno in emp.deptno%type)
    is 

    CURSOR employee is 
    select * from emp 
    where deptno = p_deptno;

    v_employee  employee%rowtype;

    dept_employee_number number:=0;

    dept_total_sal number :=0;

    dept_max_salary number :=0;

    dept_avg_sal number :=0;

    BEGIN
               BEGIN
                      dbms_output.put_line (p_deptno||' employee information ');
                  OPEN employee ;
                  LOOP 
                       FETCH employee into v_employee;
                       EXIT WHEN employee%notfound;
                             dbms_output.put_line  (rpad(v_employee.empno,5)||rpad(v_employee.ename,12)
                             ||rpad(v_employee.job,12)
                             ||rpad(v_employee.mgr,5)||rpad(v_employee.hiredate,12)||rpad(v_employee.sal,8)
                             ||rpad(nvl(v_employee.comm,0)  ,8)||rpad(v_employee.deptno,4));

                        dept_employee_number :=dept_employee_number+1;
                        dept_total_sal :=dept_total_sal+v_employee.sal;

                           IF dept_max_salary < v_employee.sal then 
                             dept_max_salary :=v_employee.sal;
                           END IF;
                  END LOOP ;

                     if employee%rowcount=0 then 
                      raise no_data_found ;
                     end if; 
                 CLOSE EMPLOYEE;
               EXCEPTION --inner block exception 
                    WHEN NO_DATA_FOUND THEN 
                    dbms_output.put_line('inner bock error no data found raising into outer exception block');
                    RAISE no_data_found;
                      WHEN OTHERS THEN 
                    DBMS_OUTPUT.PUT_LINE ('ERROR CODE : '||SQLCODE||CHR(10)||'ERORR MESSAGE   '||SUBSTR(SQLERRM,1,100));
               END ;

      dept_avg_sal :=round( to_number(dept_total_sal/dept_employee_number),3);

        dbms_output.put_line ( 'employee number : '||dept_employee_number||chr(10) 
                          ||'total salary is : '||dept_total_sal||chr(10)
                          ||'max salalry is : '||dept_max_salary||chr(10)
                          ||'avrage salary : '||dept_avg_sal) ;

    EXCEPTION --outer block exception

    WHEN NO_DATA_FOUND THEN 
     dbms_output.put_line('no data found raise from inner block');
    WHEN OTHERS THEN 
    dbms_output.put_line ('outer block error;'||sqlcode||chr(10)||sqlerrm);
    END  DEPT_EMPLOYEE_INFO;

执行DEPT_EMPLOYEE_INFO(30)::正在运行,但我想捕获异常

execute DEPT_EMPLOYEE_INFO(30A);

输入参数是数字数据类型,但是如果某个传递任何其他东西那么 我们如何捕获异常?

如果我执行

这样的程序
execute DEPT_EMPLOYEE_INFO(30A); 

然后我收到错误信息,如何处理这个异常?

0 个答案:

没有答案