用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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQLServer DML操作阻塞SELECT查詢SQLServer
- 查詢某表最近5天內最後一次dml的時間
- 臨時表空間和回滾表空間使用率查詢
- 臨時表空間被佔滿的原因查詢
- MySQL查詢時間段MySql
- JPA時間段查詢
- PostgreSQL Page頁結構解析(4)- 執行DML時表佔用空間解析SQL
- Oracle 查詢佔用臨時表空間大的歷史會話和SQLOracle會話SQL
- 查詢表空間使用情況
- 表空間使用量查詢
- DML(Data Manipulation Language、資料操作語言),用於新增、刪除、更新和查詢資料庫記資料庫
- 查詢https證書到期時間HTTP
- Oracle日期時間範圍查詢Oracle
- MySQL字串轉時間戳查詢MySql字串時間戳
- iPhone序列號和保修期怎麼查?iPhone序列號查詢啟用時間查詢教程iPhone
- 蘋果啟用時間怎麼查詢?蘋果iPhone XR查詢保修日期的方法蘋果iPhone
- oracle表空間使用率查詢Oracle
- 查詢時間從前7天到當前時間
- 查詢過去一段時間內某條sql使用的臨時表空間大小SQL
- Laravel MongoDB 時間區間查詢的問題LaravelMongoDB
- ssl證書到期時間查詢方法
- 使用.NET查詢日出日落時間
- 如何實現模糊查詢時間段
- oracle11g 查詢臨時表空間的使用率和正在使用臨時表空間的使用者Oracle
- vue+element-ui根據時間查詢VueUI
- Oracle查詢回滾大事務所需時間Oracle
- ORACLE 資料庫 查詢語句與DML語句Oracle資料庫
- 查詢表空間使用情況的指令碼指令碼
- Oracle查詢表空間的每日增長量Oracle
- Hive高階操作-查詢操作Hive
- 用hash cluster表提高查詢效能 (一)
- MySQL查詢中Sending data佔用大量時間的問題處理MySql
- HANA資料庫查詢大表佔用記憶體空間 for hana 2.0資料庫記憶體
- 順序表應用6:有序順序表查詢
- 查詢時若時間為空,開始時間取今天的零點,結束時間取當前時間
- 單表查詢
- Mysql按時間分組查詢(每天|每月|每年)MySql
- mysql查詢中時間、日期加減計算MySql
- mysql查詢最近時間的一組資料MySql