Oracle 檢查表的資料變動

來源:互聯網
上載者:User

本知識點僅適用於Oracle 9i以上的版本。

查看錶的資料變動情況請使用SQL語句:select * from user_tab_modifications;

user_tab_modifications表的欄位如下,從這個表中能夠輕鬆找到表中做的修改,刪除,增加記錄的情況

注意以及使用方法:

1、但這張表不是即時更新的,預設情況15分鐘更新一次,所以你更新一張表,可能在 user_tab_modifications裡不能立刻體現出來。

2、想要即時查看也有辦法實現,那就是在執行select * from user_tab_modifications之前先執行exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;這個預存程序目的就是立刻重新整理異動資訊的

3、當執行上面的預存程序出錯時候,錯誤如下:

ERROR at line 1:

ORA-20000: Insufficient privileges

ORA-06512: at "SYS.DBMS_STATS", line 2148

ORA-06512: at "SYS.DBMS_STATS", line 14135

ORA-06512: at line 1

哈哈錯誤很明顯,沒有許可權,那麼提權!

4、為使用者提權,首先用管理員帳號登陸,授予某個賬戶執行DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO的許可權。

grant analyze any to epplm(這裡是你的使用者名稱)

5、OK提權成功,那麼返回到原帳號(epplm),再執行exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO,OK沒問題

6、此時再執行select * from user_tab_modifications,記錄出現了。

7、FLUSH_DATABASE_MONITORING_INFO預存程序之後,所有之前的操作都將被提交!

8、對於Oracle10i以及以上的版本,DML操作,都可以在該表中查到,因為這個功能預設是開啟的,如果沒有開啟,可以通過這個方法開啟:alter table t monitoring;

預存程序:

create or replace procedure Pro_Analyze_And_TableModify is

2 begin
3    dbms_output.put_line('開始執行,過程很長,請等待');
4    DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;--立刻重新整理
5    insert into TableModifications select * from user_tab_modifications;--兩個表結構一樣
6    Pro_AnalyzeTables;--執行分析表(調用上一篇的預存程序)
7    dbms_output.put_line('執行成功');
8 end Pro_Analyze_And_TableModify;

相關文章

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.