在Oracle 11g版本的SQL*Plus中提供了一个非常有特色的选项errorlogging。当开启该选项之后,会话级别的错误都会写入到指定表中,是spool选项的有益补充。spool选项会将所有的输出信息都写入到指定文件文件中,这样会造成文件内容过于臃肿和繁杂。在使用errorlogging选项后,我们将只关注那些与报错有关的信息,可以认为该选项是spool选项的精华抽取。
例子:
create table t (id number constraint pk_t primary key) ;
insert into t(id) values (1);
commit;
SQL> set errorlogging on
SQL> show errorlogging
errorlogging is ON TABLE SCOTT.SPERRORLOG
SQL> desc sperrorlog
Name Null? Type
----------- -------- --------------
USERNAME VARCHAR2(256)
TIMESTAMP TIMESTAMP(6)
SCRIPT VARCHAR2(1024)
IDENTIFIER VARCHAR2(256)
MESSAGE CLOB
STATEMENT CLOB
SQL> insert into t(id) values (1);
insert into t(id) values (1)
*
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.PK_T) violated
SQL> select timestamp,statement,message from sperrorlog;
TIMESTAMP STATEMENT MESSAGE
------------------- -------------------------------------------------- --------------------------------------------------
2012-01-06 15:30:47. insert into t(id) values (1) ORA-00001: unique constraint (SCOTT.PK_T) violated
000000