PL / SQL EXCEPTION BLOCK不起作用

时间:2013-04-30 23:20:37

标签: sql exception plsql

我有一个异常块的以下过程。当我执行此过程时,系统正在捕获错误而不是我的异常块。任何人都对我做错了什么有任何想法。感谢

    CREATE OR REPLACE PROCEDURE ADD_ORDER
       (CUST_NUM IN CUSTOMERS_T_P2.CNO%TYPE,
       EMP_NUM IN EMPLOYEE_T_P2.ENO%TYPE,
       REC_DATE IN  ORDERS_T_P2.RECEIVED%TYPE)
     IS
     BEGIN
     IF REC_DATE IS NULL THEN
       INSERT INTO ORDERS_T_P2 (ONO, CNO, ENO, RECEIVED)
        VALUES
          (ORDER_NUMBER_SEQ.NEXTVAL, CUST_NUM, EMP_NUM, SYSDATE);
     ELSE 
        INSERT INTO ORDERS_T_P2 (ONO, CNO, ENO, RECEIVED)
          VALUES
           (ORDER_NUMBER_SEQ.NEXTVAL, CUST_NUM, EMP_NUM, REC_DATE);
     END IF;

    EXCEPTION
    WHEN VALUE_ERROR THEN
       ROLLBACK WORK;
         INSERT INTO ORDER_ERRORS_T_P2 
          VALUES
          (ORDER_NUMBER_SEQ.NEXTVAL, SYSDATE, 'STRING WAS ENTERED INSTEAD OF NUMBER');
             DBMS_OUTPUT.PUT_LINE('STRING WAS ENTERED INSTEAD OF NUMBER');
       END;

1 个答案:

答案 0 :(得分:0)

VALUE_ERROR应在DECLARE块

中声明为Exception
CREATE OR REPLACE PROCEDURE ADD_ORDER
       (CUST_NUM IN CUSTOMERS_T_P2.CNO%TYPE,
       EMP_NUM IN EMPLOYEE_T_P2.ENO%TYPE,
       REC_DATE IN  ORDERS_T_P2.RECEIVED%TYPE)
     IS
VALUE_ERROR EXCEPTION;

     BEGIN
---------------