I’m currently doing some re-engineering work as I’m now unable to get information on the logic of a internal system, which was built in India (outsourcing).
In this process it would really help me if I was able to somehow determine the order in which records of a specific table was inserted (and possible updated). For some reason there has not been added any timestamp that unambiguously uncovers this, so what I’m looking for is some hidden Oracle RDBMS index/timestamp and how to get it. I guess the order in which records are returned using a select all is not random, so I guess there must be somekind of order.
I am hoping to be able to refer to this index/timestamp in the select so that it is returned as a field in a recordset. Is this possible, and how do I do it?
By default, Oracle isn’t going to track this sort of thing. You would need some sort of audit table, a column in the table, an audit log, etc. to properly retrieve this sort of information.
Assuming that you are using a reasonably recent version of Oracle (10.2 or later, certainly), the
ORA_ROWSCNpseudocolumn may be close enough. This is an upper bound on the system change number (SCN) that the row was last modified. Unless the table was built withROWDEPENDENCIESenabled, however, theORA_ROWSCNis only tracked at the block level, not at the row level. That may be close enough if you assume that all rows in a block are inserted at roughly the same point in time. Of course, that is not going to be perfect– particularly in the case where rows were deleted from a block and a subsequent insert at a much later point in time filled up the space thatDELETEoperation freed up. If you happen to get really lucky, though, the table was built withROWDEPENDENCIESenabled andORA_ROWSCNwill give you the SCN where the row was last modified (inserted or updated).The
SCN_TO_TIMESTAMPfunction can be used to convert an SCN to a timestamp but only for a relatively limited period of time (generally a matter of days) and with a limited level of granularity (+/- either 5 minutes or 3 seconds depending on the Oracle version). That’s used in most of the examples of using theORA_ROWSCNbut, unfortunately, probably isn’t going to be terribly helpful for you.