oracle DML錯誤記錄檔(筆記)

來源:互聯網
上載者:User

標籤:

DML錯誤記錄檔是oracle10gR2引入的一個類似於SQL*Loader的錯誤記錄檔功能。它的基本原理是把任何可能導致語句失敗的記錄轉移,放到一張錯誤記錄檔表中。

具體使用如下:

1、使用DBMS_ERRLOG.CREATE_ERROR_LOG來建立錯誤記錄檔表

--原表my_test表結構desc my_test  Name   Type         Nullable Default Comments ------ ------------ -------- ------- -------- SID    NUMBER                                 NAME   VARCHAR2(20) Y                         GENDER INTEGER      Y                         AGE    NUMBER       Y                         HOBBY  VARCHAR2(20) Y   --執行下面的語句,建置錯誤日誌表execute dbms_errlog.create_error_log(‘my_test‘,‘my_test_bad‘); PL/SQL procedure successfully completed.--產生的錯誤記錄檔表my_test_bad結構desc my_test_badName            Type           Nullable Default Comments --------------- -------------- -------- ------- -------- ORA_ERR_NUMBER$ NUMBER         Y                         ORA_ERR_MESG$   VARCHAR2(2000) Y                         ORA_ERR_ROWID$  UROWID(4000)   Y                         ORA_ERR_OPTYP$  VARCHAR2(2)    Y                         ORA_ERR_TAG$    VARCHAR2(2000) Y                         SID             VARCHAR2(4000) Y                         NAME            VARCHAR2(4000) Y                         GENDER          VARCHAR2(4000) Y                         AGE             VARCHAR2(4000) Y                         HOBBY           VARCHAR2(4000) Y                         

其中ORA_ERR_TAG$這個欄位可以存放使用者自訂的資料

2、在insert語句中使用my_test_bad錯誤記錄檔表

insert into my_test  (sid,name,gender,age,hobby)  values (12,‘joy‘,2,‘age‘,‘book,football,run‘)  log errors into my_test_bad; insert into my_test(sid,name,gender,age,hobby)values (12,‘joy‘,2,‘age‘,‘book,football,run‘)log errors into my_test_bad ORA-01722: 無效數字 SQL> select * from my_test_bad;--(結果不規範,用圖展示)  

  

update,delete,merge語句都可以在後面聲明錯誤記錄檔,方法相同。如:

  update my_test     set age = ‘yyy‘   where sid = 12    log errors into my_test_bad;

  

注意事項:log errors子句不引起隱式提交,也就是說,即使復原了失誤,錯誤資訊還是會儲存在錯誤記錄檔表中。

 

oracle DML錯誤記錄檔(筆記)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.