How to find out when an Oracle table was updated the last time

前端 未结 11 1736
死守一世寂寞
死守一世寂寞 2020-11-28 05:14

Can I find out when the last INSERT, UPDATE or DELETE statement was performed on a table in an Oracle database and if so, how?

A little background: The Oracle versio

相关标签:
11条回答
  • 2020-11-28 05:38

    Since you are on 10g, you could potentially use the ORA_ROWSCN pseudocolumn. That gives you an upper bound of the last SCN (system change number) that caused a change in the row. Since this is an increasing sequence, you could store off the maximum ORA_ROWSCN that you've seen and then look only for data with an SCN greater than that.

    By default, ORA_ROWSCN is actually maintained at the block level, so a change to any row in a block will change the ORA_ROWSCN for all rows in the block. This is probably quite sufficient if the intention is to minimize the number of rows you process multiple times with no changes if we're talking about "normal" data access patterns. You can rebuild the table with ROWDEPENDENCIES which will cause the ORA_ROWSCN to be tracked at the row level, which gives you more granular information but requires a one-time effort to rebuild the table.

    Another option would be to configure something like Change Data Capture (CDC) and to make your OCI application a subscriber to changes to the table, but that also requires a one-time effort to configure CDC.

    0 讨论(0)
  • 2020-11-28 05:39

    You would need to add a trigger on insert, update, delete that sets a value in another table to sysdate.

    When you run application, it would read the value and save it somewhere so that the next time it is run it has a reference to compare.

    Would you consider that "Special Admin Stuff"?

    It would be better to describe what you're actually doing so you get clearer answers.

    0 讨论(0)
  • 2020-11-28 05:40

    If the auditing is enabled on the server, just simply use

    SELECT *
    FROM ALL_TAB_MODIFICATIONS
    WHERE TABLE_NAME IN ()
    
    0 讨论(0)
  • 2020-11-28 05:45

    Please use the below statement

    select * from all_objects ao where ao.OBJECT_TYPE = 'TABLE'  and ao.OWNER = 'YOUR_SCHEMA_NAME'
    
    0 讨论(0)
  • 2020-11-28 05:52

    Ask your DBA about auditing. He can start an audit with a simple command like :

    AUDIT INSERT ON user.table
    

    Then you can query the table USER_AUDIT_OBJECT to determine if there has been an insert on your table since the last export.

    google for Oracle auditing for more info...

    0 讨论(0)
  • 2020-11-28 05:53

    Could you run a checksum of some sort on the result and store that locally? Then when your application queries the database, you can compare its checksum and determine if you should import it?

    It looks like you may be able to use the ORA_HASH function to accomplish this.

    Update: Another good resource: 10g’s ORA_HASH function to determine if two Oracle tables’ data are equal

    0 讨论(0)
提交回复
热议问题