如何查明 Oracle 中特定表的创建时间?
在Oracle中,有没有办法找出特定表的创建时间?
同样,有没有办法找出特定行的插入/最后更新时间?
In Oracle, is there a way to find out when a particular table was created?
Similarly, is there a way to find out when a particular row was inserted/last updated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将告诉您何时创建表(如果您无权访问 DBA_OBJECTS,则可以使用 ALL_OBJECTS,而不是假设您对该表具有 SELECT 权限)。
不过,从行获取时间戳的一般答案是,只有添加了列来跟踪该信息(当然,假设您的应用程序也填充了这些列),您才能获取该数据。然而,也有各种特殊情况。如果 DML 发生的时间相对较近(很可能是在过去几个小时内),您应该能够从闪回查询中获取时间戳。如果 DML 发生在最近几天(或者无论您保留归档日志多久),您可以使用 LogMiner 来提取时间戳,但这将是一个非常昂贵的操作,特别是如果您要获取许多行的时间戳。如果您在启用 ROWDEPENDENCIES(不是默认设置)的情况下构建表,则可以使用
获取该行的上次修改日期和 SCN(系统更改编号)。但默认情况下,如果没有 ROWDEPENDENCIES,SCN 仅位于块级别。
SCN_TO_TIMESTAMP
函数也无法永远将 SCN 映射到时间戳。will tell you when a table was created (if you don't have access to DBA_OBJECTS, you could use ALL_OBJECTS instead assuming you have SELECT privileges on the table).
The general answer to getting timestamps from a row, though, is that you can only get that data if you have added columns to track that information (assuming, of course, that your application populates the columns as well). There are various special cases, however. If the DML happened relatively recently (most likely in the last couple hours), you should be able to get the timestamps from a flashback query. If the DML happened in the last few days (or however long you keep your archived logs), you could use LogMiner to extract the timestamps but that is going to be a very expensive operation particularly if you're getting timestamps for many rows. If you build the table with ROWDEPENDENCIES enabled (not the default), you can use
to get the last modification date and SCN (system change number) for the row. By default, though, without ROWDEPENDENCIES, the SCN is only at the block level. The
SCN_TO_TIMESTAMP
function also isn't going to be able to map SCN's to timestamps forever.您可以查询数据字典/目录视图来查找对象的创建时间以及最后一次涉及该对象的 DDL 的时间(例如:alter table)。
“CREATED”列告诉您对象的创建时间。
“LAST_DDL_TIME”列告诉您上次对对象执行 DDL 的时间。
至于插入/更新特定行的时间,您可以使用审核列(例如“insert_timestamp”列)或使用触发器并填充审核表
You can query the data dictionary/catalog views to find out when an object was created as well as the time of last DDL involving the object (example: alter table)
The column "CREATED" tells you when the object was created.
The column "LAST_DDL_TIME" tells you when the last DDL was performed against the object.
As for when a particular row was inserted/updated, you can use audit columns like an "insert_timestamp" column or use a trigger and populate an audit table
您复制并粘贴以下代码。它将显示所有带有名称和创建日期的表
注意:将'%table_name%'替换为您要查找的表名称。
You copy and paste the following code. It will display all the tables with Name and Created Date
Note: Replace '%table_name%' with the table name you are looking for.
尝试以下查询:
SELECT sysdate FROM schema_name.table_name;
这应该显示您可能需要的时间戳。
Try this query:
SELECT sysdate FROM schema_name.table_name;
This should display the timestamp that you might need.