简体   繁体   English

Oracle Query跟踪特定日期的表更改

[英]Oracle Query to track the changes for table with context particular day

我有以下查询,它为我提供了表中最后一次DML操作发生的时间,我想对其进行一些修改以跟踪整天,以便无论特定表的上下文发生了什么变化,我都可以获得完整的历史记录当天,所以请让我知道如何在查询下方修改此内容

SELECT SCN_TO_TIMESTAMP(MAX(ORA_ROWSCN)) from mytablename;

There is a companion to scn_to_timestamp which gives you the SCN for a given time; scn_to_timestamp有一个伴侣,可为您提供给定时间的SCN。 so to see rows whose ora_rowscn is today you could do: 因此,可以查看今天是ora_rowscn行:

select * from table_a where ora_rowscn >= timestamp_to_scn(trunc(sysdate));

There are a few caveats though, of the top of my head. 不过,我要注意的是一些警告。 First, by default ora_rowscn is the same for all rows in a block , even if the rows were modified at different times. 首先, 默认情况下 ,即使在不同的时间修改了行, ora_rowscn对于块中的所有行都是相同的。 If the table was created with rowdependencies then it will only show the rows actually modified. 如果创建的表具有行rowdependencies那么它将仅显示实际修改的行。

Second, the SCN to timestamp translation is only available during the redo/flashback window, though you should be OK for 120 hours, so if you're looking on the same day or soon afterwards you shoudl be OK. 其次,SCN到时间戳的转换仅在“重做/闪回”窗口中可用,尽管您应该在120个小时内保持正常状态,所以如果您在同一天或之后查看,则应该没有问题。 See this for a bit more info. 看到这个更多的信息。

And third, you need to be a bit careful about when and how you query the data. 第三,您需要对何时以及如何查询数据有所注意。 If a change is made just before midnight but isn't committed until after midnight, and you run your query exactly at midnight to see the last changes for the day, then you won't see the uncommitted change. 如果更改是在午夜之前进行的,但是直到午夜之后才提交,并且您恰好在午夜运行查询以查看当天的最后更改,那么您将看不到未提交的更改。 And if you query again later then you won't see it because it's now a change yesterday. 而且,如果稍后再查询,您将看不到它,因为昨天它已更改。

Also see this . 请参阅此

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM