Skip to Main Content
  • Questions
  • How to find out if the records were updated

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, AJEET.

Asked: September 14, 2015 - 1:21 am UTC

Last updated: September 18, 2015 - 3:58 am UTC

Version: 11.0.2

Viewed 10K+ times! This question is

You Asked

Hi Tom, one of my customer have asked to prove that data in one of the tables have not been updated in last few months. The table have no Last_update_date / creation_date field. is there any way to prove this with some data. please advise.

and Connor said...

Here's an example from my laptop database

SQL> select created from user_objects
  2  where object_name = 'T1'
  3  and object_type = 'TABLE';

CREATED
---------
02-SEP-15

SQL> select count(*) from t1;

  COUNT(*)
----------
    180321


I create that table nearly two weeks ago, and havent touched it since. The question is now - can I show that without using any columns on the table.

We know each block has the SCN on it

SQL> select max(ora_rowscn) from t1;

MAX(ORA_ROWSCN)
---------------
        6925456


So I can convert that to a timestamp

SQL> select scn_to_timestamp(6925456) from dual;
select scn_to_timestamp(6925456) from dual
       *
ERROR at line 1:
ORA-08181: specified number is not a valid system change number
ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1



That didnt work, because we dont keep the mapping from SCN to timestamp forever. I can see that with this query

SQL> col m for 99999999999999999
SQL> select min(SCN) m from sys.smon_scn_time;

                M
------------------
           7275763

SQL> select scn_to_timestamp(7275763) from dual;

SCN_TO_TIMESTAMP(7275763)
-----------------------------------------------------------------
07-SEP-15 10.42.09.000000000 PM


So know its *at least* before September 7th. To try get a better estimate, we can take a look at our redo log activity

SQL> select *
  2  from (
  3  select SEQUENCE#, FIRST_CHANGE#, FIRST_TIME, lead(FIRST_CHANGE#) over ( order by FIRST_CHANGE#) as next_FIRST_CHANGE#
  4  from v$log_history
  5  order by FIRST_CHANGE#
  6  )
  7  where 6925456 between FIRST_CHANGE# and next_FIRST_CHANGE#;

 SEQUENCE# FIRST_CHANGE# FIRST_TIM NEXT_FIRST_CHANGE#
---------- ------------- --------- ------------------
       204       6923744 02-SEP-15            6948678


So we see that the SCN falls into a log switch period around Sep 2.

Hope this helps.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Can I go back to a year also

AJEET OJHA, September 14, 2015 - 4:04 am UTC

Thank you so much. This really helps.

I tried this for one of my tables and it worked. I will try for another table , which has not been updated for almost a year. will I be able to find this from v$log_history.
Connor McDonald
September 16, 2015 - 3:48 am UTC

Unlikely. Depends how much information you've got in your control files, amongst other things.

But now that you know about the SCN, for example, you RMAN backup (and the RMAN catalog) will have backups and SCN's present, so as long as you can see the approximate timing of a SCN, you can get a rough approximation.

Hope this helps

AJEET OJHA, September 16, 2015 - 4:13 am UTC

Thanks , This really helped me understand the solution.

More to Explore

Analytics

Analytic SQL got you confused? Check out Connor McDonald's complete video course.