需要找到 table 何时被更改
Need To find when table was altered
我在我的 oracle 数据库 的 table 中发现了一个新列,该列不存在 before.Is 有任何方法可以找到什么时候 table 已更改。
听起来你在找这个:
SELECT last_ddl_time
FROM all_objects
WHERE object_name = 'YOUR_TABLENAME'
AND object_type = 'TABLE';
您可以查看 user_objects
中的 last_ddl_time
,或者 all_objects
或 dba_objects
如果您没有作为所有者连接:
select last_ddl_time
from user_objects
where object_type = 'TABLE'
and object_name = '<your table name>'
或
select last_ddl_time
from dba_objects
where object_type = 'TABLE'
and owner = '<your table owner>'
and object_name = '<your table name>'
这将告诉您上次针对 table 执行任何 DDL 的时间;尽管如果稍后进行了任何其他更改(例如约束、列修改等),那可能不是列添加。请记住,所有者和 table 名称需要与它们存储在字典中的大小写相同 - 通常是大写(除非您使用带引号的标识符)。
快速演示:
create table t42 (id number);
Table T42 created.
select to_char(last_ddl_time, 'YYYY-MM-DD hh24:MI:SS') as last_change
from user_objects
where object_type = 'TABLE'
and object_name = 'T42';
LAST_CHANGE
-------------------
2017-05-10 11:12:18
然后一段时间后...
alter table t42 add (new_column varchar(10));
Table T42 altered.
select to_char(last_ddl_time, 'YYYY-MM-DD hh24:MI:SS') as last_change
from user_objects
where object_type = 'TABLE'
and object_name = 'T42';
LAST_CHANGE
-------------------
2017-05-10 11:14:22
在 oracle 11G 和 12C 中,我们可以启用 DDL 日志记录
alter system set enable_ddl_logging=true;
DDL 日志文件数据以 XML 格式写入位于 ... \log\ddl
的文件
我在我的 oracle 数据库 的 table 中发现了一个新列,该列不存在 before.Is 有任何方法可以找到什么时候 table 已更改。
听起来你在找这个:
SELECT last_ddl_time
FROM all_objects
WHERE object_name = 'YOUR_TABLENAME'
AND object_type = 'TABLE';
您可以查看 user_objects
中的 last_ddl_time
,或者 all_objects
或 dba_objects
如果您没有作为所有者连接:
select last_ddl_time
from user_objects
where object_type = 'TABLE'
and object_name = '<your table name>'
或
select last_ddl_time
from dba_objects
where object_type = 'TABLE'
and owner = '<your table owner>'
and object_name = '<your table name>'
这将告诉您上次针对 table 执行任何 DDL 的时间;尽管如果稍后进行了任何其他更改(例如约束、列修改等),那可能不是列添加。请记住,所有者和 table 名称需要与它们存储在字典中的大小写相同 - 通常是大写(除非您使用带引号的标识符)。
快速演示:
create table t42 (id number);
Table T42 created.
select to_char(last_ddl_time, 'YYYY-MM-DD hh24:MI:SS') as last_change
from user_objects
where object_type = 'TABLE'
and object_name = 'T42';
LAST_CHANGE
-------------------
2017-05-10 11:12:18
然后一段时间后...
alter table t42 add (new_column varchar(10));
Table T42 altered.
select to_char(last_ddl_time, 'YYYY-MM-DD hh24:MI:SS') as last_change
from user_objects
where object_type = 'TABLE'
and object_name = 'T42';
LAST_CHANGE
-------------------
2017-05-10 11:14:22
在 oracle 11G 和 12C 中,我们可以启用 DDL 日志记录
alter system set enable_ddl_logging=true;
DDL 日志文件数据以 XML 格式写入位于 ... \log\ddl