Oracle数据库如何查询指定表最近一天或者一个小时的变更记录?

各位高手:
在不能写数据库触发器,数据库没有时间戳字段的情况下,Oracle数据库如何查询指定表最近一天或者一个小时的变更记录? 包括新增、修改、删除的数据。

数据库设计的时候,加一个updatetime根据当前时间与跟新时间的时间差来做判断,因为数据要有才能判断,所以这里数据要加一个删除字段。
也就是假删数据,这样就可以判断一定时间内新增(加createtime字段)、修改、删除的数据了。

可以使用 scn_to_timestamp(ora_rowscn),知道表中存在数据的最后一次DML时间(所以,deleted掉的数据你是不知道的)
for instance:
select *,scn_to_timestamp(ora_rowscn) from test_table where scn_to_timestamp(ora_rowscn)> sysdate-1;

如果非要知道删除的数据,我觉得可以这样做,
1) create test_table_bak as select * from test_table
2) expdp your test_table
3) use flashback OR other backup to get the original table(一般公司都有备份的吧,在其他机器上还原备份)
a) check whether flashback is working
select count(1) from test_table as of timestmap to_timestamp('','yyyy-mm-dd hh24:mi:ss')
b) if your undo_retention is greater than 1 day, step a is not necessary, flashback must work.
4) comare the table and get the delete.
5) drop the test_table and impdp the backup.

Note: you may need downtime if above work will impact your app or business. So my suggestion, use option1. for deleted data, it is complex.

给分吧,纯手写这么多