select uat.table_name from user_all_tables uat 可以获得所有用户表的名称
select object_name, created,last_ddl_time from user_objects order by last_ddl_time desc 获得所有用户对象(包括表)的创建和最后修改时间
select object_name, created, timestamp from user_objects order by timestamp desc
----------created:对象的创建时间
----------last_ddl_time:跟对象相关的(不一定是改变对象的结构,也可以是其他相关,如,如果此对象是表,则----------将该表的select权限赋给其他用户也会改变这个字段的值)最后ddl操作的执行时间
----------timestamp:对象自身结构发生改变的时间,比如删除字段、添加字段等
select * from cx_pt_tubular_order;
delete from cx_pt_tubular_order;
//应该是一周
select * from cx_pt_tubular_order as of timestamp to_Date('2016-02-18 11:00:00', 'yyyy-mm-dd hh24:mi:ss')
insert into cx_pt_tubular_order select * from cx_pt_tubular_order as of timestamp to_Date('2016-01-16 11:00:00', 'yyyy-mm-dd hh24:mi:ss')
select * from cx_pt_tubular_order as of timestamp sysdate;
------------
Flashback query(闪回查询)原理
Oracle根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回。
Flashback query(闪回查询)前提:
SQL> show parameter undo;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
其中undo_management = auto,设置自动undo管理(AUM),该参数默认设置为:auto;
Undo_retention = n(秒),设置决定undo最多的保存时间,其值越大,就需要越多的undo表空间的支持。修改undo_retention的命令如下:
SQL> alter system set undo_retention = 3600;
System altered
闪回实现方式
获取数据删除前的一个时间点或scn,如下:
注:推荐使用scn,由于oracle9i中,因为scn与时间点的同步需要5分钟,如果最近5分钟之内的数据需要Falshback query查询,可能会查询丢失,而scn则不存在这个问题。Oracle10g中这个问题已修正(scn与时间点的大致关系,可以通过logmnr分析归档日志获得)。
Falshback query查询的局限:
闪回查询无法恢复到表结构改变之前,因为闪回查询使用的是当前的数据字典。
受到undo_retention参数的影响,对于undo_retention之前的数据,Flashback不保证能Flashback成功。
对drop,truncate等不记录回滚的操作,不能恢复。
普通用户使用dbms_flashback包,必须通过管理员授权。命令如下:
SQL>grant execute on dbms_flashback to scott;
truncate table cx_pt_tubular_order;
-------------------
select object_name,original_name,partition_name,type,ts_name,createtime,droptime from recyclebin;
FLASHBACK TABLE caishi TO BEFORE DROP;
查看所有表结构
select t.TABLE_NAME 表名,
t.COLUMN_ID 序号,
t.COLUMN_NAME 字段名,
t.DATA_TYPE 类型,
t. DATA_LENGTH 长度,
t.NULLABLE 是否为空
from user_tab_columns;