Monday, August 25, 2008

Oracle: How to capture errors using "Log Errors Into" Clause

1) Create an error table to capture the errors from Insert, Update and Delete. To create this table,use Oracle's built in create_error_log function

Exec dbms_errlog.create_error_log("SOURCE_TABLE")

SOURCE_TABLE: Replace SOURCE_TABLE with name of your table. By default, error table will be prefixed by "ERR$_"

If you want to create a error table with a different name,

Exec dbms_errlog.create_error_log("SOURCE_TABLE","ERROR_TABLE_NAME")

By Default Error table will contain all columns from source table.
If your source_table contains long or blob columns, you need to skip them in the error table

Exec dbms_errlog.create_error_log("SOURCE_TABLE", skip_unsupported =>true)

Example: Insert into table_name ( col1,col2....) Values (Col1,Col2....)
log errors into err$_table_name
reject limit unlimited;

Update table_name
Set Col1 = ....
Where.....
log errors into err$_table_name
reject limit unlimited;

Delete table_name
Where.....
log errors into err$_table_name
reject limit unlimited;

If you don't use reject limit unlimited your transaction will fail and only 1 record will be inserted in the err$ table.

No comments:

Post a Comment