如何查明 Oracle 中特定表的创建时间?

发布于 2024-10-07 22:51:35 字数 65 浏览 4 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

怪异←思 2024-10-14 22:51:35
SELECT created
  FROM dba_objects
 WHERE object_name = <<your table name>>
   AND owner = <<owner of the table>>
   AND object_type = 'TABLE'

将告诉您何时创建表(如果您无权访问 DBA_OBJECTS,则可以使用 ALL_OBJECTS,而不是假设您对该表具有 SELECT 权限)。

不过,从行获取时间戳的一般答案是,只有添加了列来跟踪该信息(当然,假设您的应用程序也填充了这些列),您才能获取该数据。然而,也有各种特殊情况。如果 DML 发生的时间相对较近(很可能是在过去几个小时内),您应该能够从闪回查询中获取时间戳。如果 DML 发生在最近几天(或者无论您保留归档日志多久),您可以使用 LogMiner 来提取时间戳,但这将是一个非常昂贵的操作,特别是如果您要获取许多行的时间戳。如果您在启用 ROWDEPENDENCIES(不是默认设置)的情况下构建表,则可以使用

SELECT scn_to_timestamp( ora_rowscn ) last_modified_date,
       ora_rowscn last_modified_scn,
       <<other columns>>
  FROM <<your table>>

获取该行的上次修改日期和 SCN(系统更改编号)。但默认情况下,如果没有 ROWDEPENDENCIES,SCN 仅位于块级别。 SCN_TO_TIMESTAMP 函数也无法永远将 SCN 映射到时间戳。

SELECT created
  FROM dba_objects
 WHERE object_name = <<your table name>>
   AND owner = <<owner of the table>>
   AND object_type = 'TABLE'

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

SELECT scn_to_timestamp( ora_rowscn ) last_modified_date,
       ora_rowscn last_modified_scn,
       <<other columns>>
  FROM <<your table>>

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.

晨敛清荷 2024-10-14 22:51:35

您可以查询数据字典/目录视图来查找对象的创建时间以及最后一次涉及该对象的 DDL 的时间(例如:alter table)。

select * 
  from all_objects 
 where owner = '<name of schema owner>'
   and object_name = '<name of 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)

select * 
  from all_objects 
 where owner = '<name of schema owner>'
   and object_name = '<name of 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

陌路终见情 2024-10-14 22:51:35

您复制并粘贴以下代码。它将显示所有带有名称和创建日期的表

SELECT object_name,created FROM user_objects
WHERE object_name LIKE  '%table_name%'
AND object_type = 'TABLE'; 

注意:'%table_name%'替换为您要查找的表名称。

You copy and paste the following code. It will display all the tables with Name and Created Date

SELECT object_name,created FROM user_objects
WHERE object_name LIKE  '%table_name%'
AND object_type = 'TABLE'; 

Note: Replace '%table_name%' with the table name you are looking for.

遇到 2024-10-14 22:51:35
SELECT CREATED FROM USER_OBJECTS WHERE OBJECT_NAME='<<YOUR TABLE NAME>>'
SELECT CREATED FROM USER_OBJECTS WHERE OBJECT_NAME='<<YOUR TABLE NAME>>'
内心荒芜 2024-10-14 22:51:35

尝试以下查询:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文