1. 程式人生 > >Oracle 11g 記錄DML錯誤數據

Oracle 11g 記錄DML錯誤數據

error 創建 建表 expr nal blog eject tps exceptio

[From] https://oracle-base.com/articles/10g/dml-error-logging-10gr2

需要記錄下大量DML操作中出錯的具體record,看到有兩種方案,一種是使用批量DML操作bulk collect並帶上save exceptions子句,然後做處理。稍微繁瑣,不想使用。於是用另一種方案,就是在DML語句後面跟上LOG ERRORS。

LOG ERRORS [INTO [schema.]table] [(‘simple_expression‘)] [REJECT LIMIT integer|UNLIMITED]



The optional INTO clause allows you to specify the name of the error logging table. If you omit this clause, the the first 25 characters of the base table name are used along with the "ERR$_" prefix.

The simple_expression is used to specify a tag that makes the errors easier to identify. This might be a string or any function whose result is converted to a string.

The REJECT LIMIT is used to specify the maximum number of errors before the statement fails. The default value is 0 and the maximum values is the keyword UNLIMITED. For parallel DML operations, the reject limit is applied to each parallel server.

其中,這個錯誤記錄表需要先創建,可以使用包 exec DBMS_ERRLOG.CREATE_ERROR_LOG(‘target_table‘); 來創建。第一個參數就是需要被記錄DML操作的目標表。如果不附加參數,則默認會創建表名為ERR&_target_table的表。之後就可以使用LOG ERRORS了,使用默認表名時,log errors 後面可以不需要into。

Oracle 11g 記錄DML錯誤數據