oracle的异常处理

  /**
     写入自动施封命令:【同步webservice使用】
     wyg 2017-03-12
  */
  PROCEDURE ISDT_VEHICLE_AutoLock(P_WID       IN VARCHAR2,
                                  P_VEHICLENO IN VARCHAR2,
                                  P_STATE     OUT INT,
                                  P_MSG       OUT VARCHAR2) IS
  BEGIN
    insert into t_isdt_elockautorequest
      (requestid,
       wid,
       vehicleno,
       operatetype,
       created_date,
       last_updated_date)
    values
      (sys_guid(), P_WID, P_VEHICLENO, 1, sysdate, sysdate);
    COMMIT;
    P_STATE := 1;
    P_MSG   := 'success';
  EXCEPTION
    WHEN OTHERS THEN
      rollback;
      P_STATE := 0;
      P_MSG   := SUBSTRB('line:' || dbms_utility.format_error_backtrace() ||
                         ' Occur error;' || SQLCODE || ',' || SQLERRM,
                         1,
                         200);
  END;

  

 EXCEPTION
    WHEN DUP_VAL_ON_INDEX THEN
      INSERT INTO t_isdt_vehicle_track_err
        (car_num,
         gpstime,
         lon,
         lat,
         speed,
         direction,
         odometer,
         statusstr,
         placeroad,
         created_date,
         CREATED_BY)
      VALUES
        (P_CAR_NUM,
         P_GPSTIME,
         P_LON,
         P_LAT,
         P_SPEED,
         P_DIRECTION,
         P_ODOMETER,
         P_STATUSSTR,
         P_PLACEROAD,
         SYSDATE,
         1);
      P_STATE := 0;
      P_MSG   := SUBSTRB('line:' || dbms_utility.format_error_backtrace() ||
                         ' Occur error;' || SQLCODE || ',' || SQLERRM,
                         1,
                         200);
      COMMIT;
    WHEN OTHERS THEN
      ROLLBACK;
      P_STATE := 0;
      P_MSG   := SUBSTRB('line:' || dbms_utility.format_error_backtrace() ||
                         ' Occur error;' || SQLCODE || ',' || SQLERRM,
                         1,
                         200);

显示结果:

ine:ORA-06512: 在 "employeDB.__DATA_SYNC", line 512
Occur error;-12899,ORA-12899: 列 "EMS"."T_ISDT_ELOCKAUTOREQUEST"."WID" 的值太大 (实际值: 137, 最大值: 50)

posted @ 2017-03-12 18:27  闲莫等  阅读(219)  评论(0编辑  收藏  举报