Get all table's row updated after a specific time

…衆ロ難τιáo~ 提交于 2019-12-12 03:39:25

问题


Background: I have an oracle table, the table doesn't have any specific column as timestamp while table creation script. This table can have millions of rows.

Example:

Employee {Emp_No, Name, Manager,Division, Role, Region}

My quest: If any updates happened through a job on that table, can i know which all rows got updated. Does oracle have any internal timestamp for each row which i can leverage. Can i use it in query to get all records.

Reason: I need to show my team those ambiguous records weren't updated by the job we all are suspecting.


回答1:


Oracle has ORA_ROWSCN Pseudocolumn. This columns returns "the conservative upper bound system change number (SCN)" of last transaction made on row or data block. This is a good estimate for when the block or row was last changed.

If your table is create with ROWDEPENDENCIES, ORA_ROWSCN returns scn for row. NOROWDEPENDENCIES is the default, in which case Oracle tracks SCN at the block level.

SCN_TO_TIMESTAMP allows you to converto scn to timestamp but for old scn it raises exception.




回答2:


Approximate update time can be retrieved with SCN_TO_TIMESTAMP(ORA_ROWSCN)

For each row, ORA_ROWSCN returns the conservative upper bound system change number (SCN) of the most recent change to the row. This pseudocolumn is useful for determining approximately when a row was last updated. It is not absolutely precise, because Oracle tracks SCNs by transaction committed for the block in which the row resides.

https://docs.oracle.com/cd/B19306_01/server.102/b14200/pseudocolumns007.htm



来源:https://stackoverflow.com/questions/43003024/get-all-tables-row-updated-after-a-specific-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!