Oracle實現對錶dml錯誤記錄日誌

來源:互聯網
上載者:User

DBMS_ERRLOG提供了一個預存程序CREATE_ERROR_LOG,這個預存程序建立一個錯誤記錄檔表,當DML出錯時,操作不會終止和復原,而是將相關的錯誤寫到錯誤記錄檔表中。

CREATE_ERROR_LOG不支援一些資料類型:LONG, CLOB,BLOB, BFILE, and ADT。
 
    簡單樣本:

SQL> create unique index ind_test00_a on test00(a);

Index created.

SQL> EXEC DBMS_ERRLOG.CREATE_ERROR_LOG('TEST00','TEST00_ERROR_LOG');

PL/SQL procedure successfully completed.

SQL> desc test00
 Name                                                                    Null?  Type
 -------------------------------------------------------------------------------- -------------------------------------------------
 A                                                                                NUMBER(10)
 B                                                                                NUMBER(10)

SQL> desc test00_error_log
 Name                                                                    Null?  Type
 -------------------------------------------------------------------------------- -------------------------------------------------
 ORA_ERR_NUMBER$                                                                  NUMBER
 ORA_ERR_MESG$                                                                    VARCHAR2(2000)
 ORA_ERR_ROWID$                                                                  ROWID
 ORA_ERR_OPTYP$                                                                  VARCHAR2(2)
 ORA_ERR_TAG$                                                                    VARCHAR2(2000)
 A                                                                                VARCHAR2(4000)
 B                                                                                VARCHAR2(4000)
SQL> INSERT INTO TEST00 values(1,1) LOG ERRORS INTOTEST00_ERROR_LOG REJECT LIMIT 1;

1 row created.

SQL> INSERT INTO TEST00 values(2,2) LOG ERRORS INTOTEST00_ERROR_LOG REJECT LIMIT 1;

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test00;

        A        B
---------- ----------
        1        1
        2        2

SQL> select * from test00_error_log;

no rows selected

SQL> INSERT INTO TEST00 values(2,2) LOG ERRORS INTOTEST00_ERROR_LOG REJECT LIMIT 1;
---插入重複資料,未報錯,操作正常進行。

0 rows created.

SQL>commit;   

Commit complete.

SQL> select * from test00;  ---資料未插入到表中,結果是正確的

        A        B
---------- ----------
        1        1
        2        2

SQL> select * from test00_error_log; ---錯誤操作記錄到了錯誤記錄檔表中

ORA_ERR_NUMBER$ORA_ERR_MESG$                    ORA_ERR_ROWID$                  ORA_ERR_OPTYP$        ORA_ERR_TAG$          A        B
--------------- ------------------------------------------------------------------ -------------------------------------------- ---------- ----------
            1 ORA-00001: unique constraint(WXL                                  I                                            2        2
              UN.IND_TEST00_A) violated


SQL>

附錄:
CREATE_ERROR_LOG ProcedureParameters
CREATE_ERROR_LOG參數:

Parameter Description

dml_table_name

The name of the DML table to basethe error logging table on. The name can be fully qualified (forexample, emp, scott.emp,"EMP", "SCOTT"."EMP"). If a namecomponent is enclosed in double quotes, it will not be uppercased.

err_log_table_name

The name of the error loggingtable you will create.

The default is the first 25characters in the name of the DML table prefixed with'ERR$_'. Examples are the following:

dml_table_name:'EMP', err_log_table_name:'ERR$_EMP'

dml_table_name:'"Emp2"', err_log_table_name:'ERR$_Emp2'

err_log_table_owner

The name of the owner of theerror logging table. You can specify the owner indml_table_name. Otherwise, the schema of the currentconnected user is used.

err_log_table_space

The tablespace the error loggingtable will be created in. If not specified, the default tablespacefor the user owning the DML error logging table will beused.

skip_unsupported

When set to TRUE,column types that are not supported by error logging will beskipped over and not added to the error logging table.

When set to FALSE,an unsupported column type will cause the procedure toterminate.

The default isFALSE.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.