Oracle:如何知道表中何时添加了列?

时间:2017-12-13 09:31:25

标签: oracle

想问一下,当列添加到表中时,我是否可以检索历史记录?我现在正在寻找闪回。感谢。

2 个答案:

答案 0 :(得分:2)

您可以使用USER / ALL / DBA_OBJECTS表来查找表格上的最后更改。见下文:

SELECT OBJECT_NAME,
       OBJECT_TYPE,
       TO_CHAR (CREATED, 'DD-MM-YY HH24:MI:SS') CREATED,
       TO_CHAR (LAST_DDL_TIME, 'DD-MM-YY HH24:MI:SS') LAST_DDL
  FROM USER_OBJECTS
 WHERE OBJECT_NAME = <Your_Tablename>;

答案 1 :(得分:-1)

如果搜索期间有存档日志。 您必须使用实用程序LogMiner。 因为发出LAST_DDL_TIME的查询将返回ddl的最后一次执行。

   select  TO_char(created, 'DD-MM-YYYY HH24:MI'),TO_CHAR(last_ddl_time, 'DD-MM-YYYY HH24:MI' )   from all_objects
where object_name='TEST2'
and owner='MANAGER'


TO_CHAR(CREATED,'DD-MM-YYYYHH24:MI')       TO_CHAR(LAST_DDL_TIME,'DD-MM-YYYYHH24:MI')       
------------------------------------------ ----------------------------- 
14-12-2017 09:40                           14-12-2017 10:16 

EXECUTE DBMS_LOGMNR.add_logfile(LOGFILENAME => '/oracle/app/oracle/product/11.2/admin/edcu/arc_redo_log/1_39306_769799469.dbf', OPTIONS => DBMS_LOGMNR.NEW); 
EXECUTE DBMS_LOGMNR.add_logfile(LOGFILENAME => '/oracle/app/oracle/product/11.2/admin/edcu/arc_redo_log/1_39307_769799469.dbf', OPTIONS => DBMS_LOGMNR.addfile); 
EXECUTE DBMS_LOGMNR.add_logfile(LOGFILENAME => '/oracle/app/oracle/product/11.2/admin/edcu/arc_redo_log/1_39308_769799469.dbf', OPTIONS => DBMS_LOGMNR.addfile); 
EXECUTE DBMS_LOGMNR.add_logfile(LOGFILENAME => '/oracle/app/oracle/product/11.2/admin/edcu/arc_redo_log/1_39309_769799469.dbf', OPTIONS => DBMS_LOGMNR.addfile); 
EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);

SELECT 
to_char(timestamp,'DD-MM-YYYY HH24:MI:SS'),
operation,username,  
os_username,
machine_name,
session_info,
sql_redo

 FROM v$logmnr_contents
where 
seg_owner='MANAGER' and  seg_name='TEST2'

14-12-2017 09:40:20 DDL     MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  create table test2 (p1 number);
14-12-2017 09:40:47 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1") values (HEXTORAW('c117'));
14-12-2017 09:40:53 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1") values (HEXTORAW('c119'));
14-12-2017 09:40:57 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1") values (HEXTORAW('c137'));
14-12-2017 09:41:01 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1") values (HEXTORAW('c20219'));
14-12-2017 09:41:45 DDL     MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  alter table test2 add (p2 varchar2(200));
14-12-2017 09:42:12 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1","COL 2") values (HEXTORAW('c20219'),HEXTORAW('746573743220746573743120'));
14-12-2017 09:42:24 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1","COL 2") values (HEXTORAW('c2021a'),HEXTORAW('746573743420746573743420'));
14-12-2017 09:46:24 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1","COL 2") values (HEXTORAW('c2021a'),HEXTORAW('746573743420746573743420'));
14-12-2017 09:46:25 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1","COL 2") values (HEXTORAW('c2021a'),HEXTORAW('746573743420746573743420'));
14-12-2017 09:46:26 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1","COL 2") values (HEXTORAW('c2021a'),HEXTORAW('746573743420746573743420'));
14-12-2017 09:46:27 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1","COL 2") values (HEXTORAW('c2021a'),HEXTORAW('746573743420746573743420'));
14-12-2017 09:46:28 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("COL 1","COL 2") values (HEXTORAW('c2021a'),HEXTORAW('746573743420746573743420'));
14-12-2017 09:54:37 DDL     MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN   comment on table test2 is  'test';
14-12-2017 10:16:36 DDL     MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  alter table test2 add  (p3 varchar2(100));
14-12-2017 10:17:07 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("P1","P2","P3") values ('125','test6','test4 ');
14-12-2017 10:17:08 INSERT  MANAGER DeminDV KRW\IVC-PTK-DEMIN   login_username=MANAGER client_info= OS_username=DeminDV Machine_name=KRW\IVC-PTK-DEMIN  insert into "MANAGER"."TEST2"("P1","P2","P3") values ('125','test6','test4 ');