SQL * Plus错误日志记录截断不起作用

时间:2013-06-08 22:16:46

标签: oracle sqlplus

我的脚本使用SQL*Plus error logging来跟踪安装过程中的错误。 脚本以这样的方式开始 - 它们启用erorr日志记录并截断任何现有条目:

SQL> set errorlogging on truncate
SQL> select * from table_does_not_exist;
select * from table_does_not_exist
              *
ERROR at line 1:
ORA-00942: table or view does not exist

然后在最后我查询sperrorlog以查看出现了什么问题:

SQL> select statement from sperrorlog;

STATEMENT
--------------------------------------------------------------------------------
select * from table_does_not_exist

但是偶尔truncate不起作用,我从以前的安装中得到错误。为什么truncate无效?

2 个答案:

答案 0 :(得分:2)

尽管它的名称,SQL * Plus错误日志记录truncate实际上并没有截断表。它删除数据但不提交。

此SQL * Plus会话启用错误记录并创建错误。另一个启用错误记录和截断的调用确实清除了数据,但回滚撤消了截断。

SQL> set errorlogging on truncate
SQL> select * from table_does_not_exist;
select * from table_does_not_exist
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> commit;

Commit complete.

SQL> set errorlogging on truncate
SQL> select statement from sperrorlog;

no rows selected

SQL> rollback;

Rollback complete.

SQL> select statement from sperrorlog;

STATEMENT
--------------------------------------------------------------------------------
select * from table_does_not_exist

SQL>

为安全起见,您应始终在commit之后发出set errorlogging on truncate

答案 1 :(得分:0)

  

为安全起见,您应该在truncate

上设置错误记录后立即发出提交

或者,执行显式TRUNCATE ,这会将隐式提交作为DDL语句。当然,这就像不使用truncate选项一样,但rollback的问题也是如此。我找到了回滚问题的解决方法,并在我的博客SQL*Plus error logging – workaround for ROLLBACK issue

中分享了该问题

回到你的问题,我更信任一个明确的截断:

SQL> set errorlogging on
SQL> select * from table_does_not_exist;
select * from table_does_not_exist
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select statement from sperrorlog;

STATEMENT
----------------------------------------
select * from table_does_not_exist

SQL> truncate table sperrorlog;

Table truncated.

SQL> select statement from sperrorlog;

no rows selected

SQL> rollback;

Rollback complete.

SQL> select statement from sperrorlog;

no rows selected

SQL>

或者,您可以对 sperrorlog 表使用全局临时表,并将其设为 on commit delete rows

相关问题