Oracle record history using as of timestamp within a range

1,587

Solution 1

Yes, like this:

SQL> select sal from emp where empno=7369;

       SAL
----------
      5800

SQL> update emp set sal = sal+100 where empno=7369;

1 row updated.

SQL> commit;

Commit complete.

SQL> update emp set sal = sal-100 where empno=7369;

1 row updated.      

SQL> commit;

Commit complete.

SQL> select empno, sal, versions_starttime,versions_xid
  2  from emp
  3  versions between timestamp sysdate-1 and sysdate
  4  where empno=7369;

     EMPNO        SAL VERSIONS_STARTTIME                                                          VERSIONS_XID
---------- ---------- --------------------------------------------------------------------------- --
      7369       5900 11-DEC-08 16.05.32                                                          0014001300002A74
      7369       5800 11-DEC-08 16.03.32                                                          000D002200012EB1
      7369       5800

Note that how far back you can go is limited by the UNDO_RETENTION parameter, and will typically be hours rather than days.

Solution 2

One note to be aware of is that this sort of flashback query relies on UNDO information that is written to the UNDO tablespace. And that information is not retained forever-- most production systems under reasonable load are not going to have 24 hours of UNDO information available.

Depending on the Oracle version, you may need to set the UNDO_RETENTION parameter to a value longer than the time period you are trying to flashback through.

Share:
1,587
Pranjal Choladhara
Author by

Pranjal Choladhara

Updated on December 12, 2020

Comments

  • Pranjal Choladhara
    Pranjal Choladhara over 3 years

    I have a running application in Play Store. I've tested and successfully updated my application three times. Suddenly, I had to change my laptop and reconfigured everything, i.e. Android Studio, JDK, SDK and everything. I knew that the signed key file is important for updating my application. So I backed up my project and the file.

    Now I'm going to update my application again and I've noticed that my SHA1 key is changed. I cannot test my G+ login integrated with my app. I think that same problem will arise in GCM also. What should I do?

    • CommonsWare
      CommonsWare about 8 years
      You are not signing with the same keystore as you did before.
    • Doug Stevenson
      Doug Stevenson about 8 years
      When you say you can't test your app, do you mean in debug mode, not release mode?
    • Pranjal Choladhara
      Pranjal Choladhara about 8 years
      I've attached my phone with my laptop. Then I've run my application from android studio. Now I cannot connect my G+ login.
    • Pranjal Choladhara
      Pranjal Choladhara about 8 years
      @Doug Stevenson - Yes, I mean in debug mode, not release mode.
    • fillobotto
      fillobotto over 7 years
      If it happens in debug mode is normal because it's not used the keystroke that you use to sign the app for the Play Store, unless you create one more signature and you configured the project to use that key to sign the app even in debug mode.