[bbk5355]第18集 - Chapter 08 - Handling Exceptions(01)
2013-04-24 12:10
567 查看
Exception Types
Predefined Oracle Server --Implicitly raisedNon-predefined Oracle Server --Implicitly raised
User-defined --Explicitly raised
Syntax to Trap Exceptions
cannot insert NULLDECLARE e_insert_excep EXCEPTION; /* PRAGMA EXCEPTION_INIT(e_insert_excep,-01400)功能: 将异常名称e_insert_excep与error code -01400进行关联起来,以后直接引用此名称就相当于引用此代码; */ PRAGMA EXCEPTION_INIT(e_insert_excep,-01400); BEGIN INSERT INTO dept(department_id,department_name) VALUES (280,NULL); EXCEPTION WHEN e_insert_excep THEN DBMS_OUTPUT.PUT_LINE('INSERT OPERATION FAILD'); DBMS_OUTPUT.PUT_LINE(SQLERRM); END; / SQL> @2 INSERT OPERATION FAILD ORA-01400: cannot insert NULL into ("HR"."DEPT"."DEPARTMENT_NAME") PL/SQL procedure successfully completed.
EXCEPTION_INIT Directive
EXCEPTION_INIT is a complie-time command or gragma used to associate a name with an internal error code.EXCEPTION_INIT instructs the compiler to associate an identifier,declared as an EXCEPTION,with a specific error number.
Syntax:
DECLARE exception_name EXCEPTION; PRAGMA EXCEPTION_INIT(exception_name,integer);
Functions for Trapping Exceptions
SQLCODE:Returns the numeric value for the error code.SQLERRM:Returns the message associated with the erro number.
孪生兄弟,并行出现;值被自动填充.
SQLCODE、SQLERRM是2个函数.
Functions for Trapping Exceptions
DECLARE error_code NUMBER; error_message VARCHAR2(255); BEGIN ... EXCEPTION ... WHEN OTHERS THEN ROLLBACK; error_code := SQLCODE; error_messsage :=SQLERRM; INSERT INTO errors(e_user,e_date,error_code,error_message) VALUES(USER,SYSDATE,error_code,error_message); END; /
通过上述demo延伸问题:
当BEGIN section里面的语句发生异常的时候,此时进入到EXCEPTION section,此时有ROLLBACK clause,但是紧接着又有INSERT 日志文件的语句发起了一个新的事务,那么此时就有必要进行指明ROLLBACK到哪一个事务,不ROLLBACK到即将用到的事务:
相关文章推荐
- [bbk5300]第17集 - Chapter 08 - Handling Exceptions(00)
- [bbk5364]第19集 - Chapter 08 - Handling Exceptions(02)
- Chapter3 - Exceptions And Exception Handling
- [bbk3205] 第68集 -Chapter 17-Monitoring and Detecting Lock Contention(01)
- tensorflow16《TensorFlow实战Google深度学习框架》笔记-08-01 RNN前向传播 code
- tensorflow40《TensorFlow实战》笔记-08-01 TensorFlow实现深度强化学习-策略网络 code
- 【安卓】解决 NDK 出现 error: exception handling disabled, use -fexceptions to enable 的问题
- Chapter 08–Maintaining Tablespace and Data files
- [08-01] 再斩灰鸽子Backdoor.Gpigeon.uql新变种(第3版)
- 马哥笔记08_01~~~08_04
- Error Handling with Exceptions【4】
- 再读C++ Primer 写了个小例子——运算符重载(08-01-17)
- [CHAPTER 01] 1.1 字符重排
- ffmpeg-201612[01,08,10,17,21,27,30]-bin.7z
- Chapter 12 Exceptions and Assertions
- 2018-08-01 期 MapReduce实现多表查询等值连接
- error: exception handling disabled, use -fexceptions to enable
- Chapter -09 Creating Procedures 01
- 算法练习——C++CH 08 01
- [bbk2191] 第32集 - Chapter 09-Optimizing Sore Perations(01)