用user_tab_modifications查詢表dml操作時間
今天有朋友問,如何檢視錶最後dml操作時間,查詢官方文件發現表ALL_TAB_MODIFICATIONS可以滿足需求。
我們先來看看錶ALL_TAB_MODIFICATIONS的簡介
ALL_TAB_MODIFICATIONS describes tables accessible to the current user that have been modified since the last time statistics were gathered on the tables.
Related Views
DBA_TAB_MODIFICATIONS provides such information for all tables in the database.
USER_TAB_MODIFICATIONS provides such information for tables owned by the current user. This view does not display the TABLE_OWNER column.
Note:
These views are populated only for tables with the MONITORING attribute. They are intended for statistics collection over a long period of time. For performance reasons, the Oracle Database does not populate these views immediately when the actual modifications occur. Run the FLUSH_DATABASE_MONITORING_INFO procedure in the DIMS_STATS PL/SQL package to populate these views with the latest information. The ANALYZE_ANY system privilege is required to run this procedure.
These views are populated only for tables with the MONITORING attribute. They are intended for statistics collection over a long period of time. For performance reasons, the Oracle Database does not populate these views immediately when the actual modifications occur. Run the FLUSH_DATABASE_MONITORING_INFO procedure in the DIMS_STATS PL/SQL package to populate these views with the latest information. The ANALYZE_ANY system privilege is required to run this procedure.
Column Datatype NULL Description
TABLE_OWNER VARCHAR2(30) Owner of the modified table.
TABLE_NAME VARCHAR2(30) Name of the modified table
PARTITION_NAME VARCHAR2(30) Name of the modified partition
SUBPARTITION_NAME VARCHAR2(30) Name of the modified subpartition
INSERTS NUMBER Approximate number of inserts since the last time statistics were gathered
UPDATES NUMBER Approximate number of updates since the last time statistics were gathered
DELETES NUMBER Approximate number of deletes since the last time statistics were gathered
TIMESTAMP DATE Indicates the last time the table was modified
DROP_SEGMENTS NUMBER Number of partition and subpartition segments dropped since the last analyze
TABLE_OWNER VARCHAR2(30) Owner of the modified table.
TABLE_NAME VARCHAR2(30) Name of the modified table
PARTITION_NAME VARCHAR2(30) Name of the modified partition
SUBPARTITION_NAME VARCHAR2(30) Name of the modified subpartition
INSERTS NUMBER Approximate number of inserts since the last time statistics were gathered
UPDATES NUMBER Approximate number of updates since the last time statistics were gathered
DELETES NUMBER Approximate number of deletes since the last time statistics were gathered
TIMESTAMP DATE Indicates the last time the table was modified
DROP_SEGMENTS NUMBER Number of partition and subpartition segments dropped since the last analyze
看到官方叫views,我們還是稱呼為表吧,下面做個實驗,環境是11g
[oracle@cent6224 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Fri May 4 12:33:49 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning and Data Mining options
SQL> create user modifytest identified by modifytest;
User created.
SQL> grant connect,resource to modifytest;
Grant succeeded.
SQL> conn modifytest/modifytest;
Connected.
SQL> set line 200
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SQL> select * from USER_TAB_MODIFICATIONS;
Connected.
SQL> set line 200
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SQL> select * from USER_TAB_MODIFICATIONS;
no rows selected
SQL> select table_name,inserts,updates,deletes from user_tab_modifications;
no rows selected
SQL> create table t(a number);
Table created.
SQL> select monitoring from user_tables where table_name='T';
MON
---
YES
---
YES
SQL> select * from USER_TAB_MODIFICATIONS;
no rows selected
SQL> insert into t values(1);
1 row created.
SQL> select * from USER_TAB_MODIFICATIONS;
no rows selected
SQL> commit;
Commit complete.
SQL> select * from USER_TAB_MODIFICATIONS;
no rows selected
SQL> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
BEGIN DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO; END;
BEGIN DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO; END;
*
ERROR at line 1:
ORA-20000: Insufficient privileges
ORA-06512: at "SYS.DBMS_STATS", line 4535
ORA-06512: at "SYS.DBMS_STATS", line 25376
ORA-06512: at line 1
ERROR at line 1:
ORA-20000: Insufficient privileges
ORA-06512: at "SYS.DBMS_STATS", line 4535
ORA-06512: at "SYS.DBMS_STATS", line 25376
ORA-06512: at line 1
SQL> conn / as sysdba
Connected.
SQL> grant analyze any to modifytest;
Grant succeeded.
SQL> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;
PL/SQL procedure successfully completed.
SQL> select * from USER_TAB_MODIFICATIONS;
TABLE_NAME PARTITION_NAME SUBPARTITION_NAME INSERTS UPDATES DELETES TIMESTAMP TRU DROP_SEGMENTS
------------------------------ ------------------------------ ------------------------------ ---------- ---------- ---------- ------------------- --- -------------
T 1 0 0 2012-05-04 12:46:01 NO 0
SQL> analyze table t compute statistics;
------------------------------ ------------------------------ ------------------------------ ---------- ---------- ---------- ------------------- --- -------------
T 1 0 0 2012-05-04 12:46:01 NO 0
SQL> analyze table t compute statistics;
Table analyzed.
SQL> select * from USER_TAB_MODIFICATIONS;
no rows selected
SQL>
實驗後發現analyze後表USER_TAB_MODIFICATIONS會清空
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12457158/viewspace-722429/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 表中出現碎片,造成查詢、DML操作變慢
- 查詢某表最近5天內最後一次dml的時間
- 應用ROWDEPENDENCIES行級跟蹤,查詢oracle表中資料行上最後的DML時間Oracle
- SQLServer DML操作阻塞SELECT查詢SQLServer
- 如何查詢DML操作的詳細記錄
- oracle 表空間,臨時表空間使用率查詢Oracle
- 查詢oracle 表的大小和表的建立時間Oracle
- 查詢某個表最後修改時間
- 查詢一個表插入資料的時間,按BLOCK時間BloC
- 臨時表空間的空間使用情況查詢
- oracle 表(table)上最後一次 DML時間、行(row)上最後DML時間Oracle
- 表的建立修改及增刪改查-DML操作
- Oracle下查詢臨時表空間佔用率Oracle
- 臨時表空間和回滾表空間使用率查詢
- oracle表空間查詢Oracle
- 表空間大小查詢
- 表空間查詢資訊
- 臨時表空間被佔滿的原因查詢
- JPA時間段查詢
- MySQL查詢時間段MySql
- 線性時間查詢
- SQL時間段查詢SQL
- Oracle中定位資料表的最近DML時間Oracle
- 表空間查詢和管理
- 表空間相關查詢
- 怎樣查詢一個表的最後更新時間?
- Oracle 查詢佔用臨時表空間大的歷史會話和SQLOracle會話SQL
- Mysql 查詢時間轉換MySql
- PostgreSQL Page頁結構解析(4)- 執行DML時表佔用空間解析SQL
- 蘋果啟用時間怎麼查詢?蘋果iPhone XR查詢保修日期的方法蘋果iPhone
- ORACLE Temporary Tables臨時表更適合做插入和查詢操作Oracle
- 表空間使用量查詢
- 查詢表空間使用情況
- SAP IQ DML操作產生表鎖(不是行鎖),同時DML同一個表預設直接報錯
- Oracle日期時間範圍查詢Oracle
- Mysql中查詢系統時間MySql
- 查詢時間從前7天到當前時間
- iPhone序列號和保修期怎麼查?iPhone序列號查詢啟用時間查詢教程iPhone