Oracle: flashback version query example

Source: Internet
Author: User

Flashback version query is not a new feature of Oracle, but the 10g and 11g functions are enhanced on the basis of 9i, which may be used in some occasions. The following example shows his concept;

 
  1. ConnectedToOracleDatabase11g Enterprise Edition Release 11.2.0.1.0
  2. ConnectedAsHr
  3. SQL> showUser;
  4. User Is "Hr"
  5. SQL> show parameter undo
  6. NAMETYPE VALUE
  7. -----------------------------------------------------------------------------
  8. Undo_management string AUTO
  9. Undo_retentionInteger9000
  10. Undo_tablespace string UNDOTBS1
  11. SQL>Truncate TableT1;
  12. TableTruncated
  13. SQL>SelectSystimestampFromDual;
  14. SYSTIMESTAMP
  15. --------------------------------------------------------------------------------
  16. 31-DEC-11 02.58.26.560000 PM + 08:00
  17. SQL>Insert IntoT1Values(1,'Jash');
  18. 1 row inserted
  19. SQL>Commit;
  20. CommitComplete
  21. SQL>UpdateT1Set Name='Bob' WhereId = 1;
  22. 1 row updated
  23. SQL>Commit;
  24. CommitComplete
  25. SQL>SelectSystimestampFromDual;
  26. SYSTIMESTAMP
  27. -----------------------------------------
  28. 31-DEC-11 02.5900004.318000 PM +
  29. SQL>
  30. SQL>SELECTVersions_startscn, versions_starttime,
  31. 2 versions_endscn, versions_endtime,
  32. 3 versions_xid, versions_operation,
  33. 4 id,Name
  34. 5FROMHr. t1
  35. 6 VERSIONSBETWEEN TIMESTAMP
  36. 7 TO_TIMESTAMP ('2017-12-31 14:58:26','Yyyy-MM-DD HH24: MI: ss')
  37. 8ANDTO_TIMESTAMP ('2017-12-31 14:59:04','Yyyy-MM-DD HH24: MI: ss');

The title of the query result column is a little long. I have truncated it. Otherwise, the whole row cannot be displayed. Check the column title against the preceding query statement;

 
  1. SQL>
  2. SQL>Insert IntoT1Values(2,'Clark');
  3. 1 row inserted
  4. SQL>Insert IntoT1Values(3,'Pig');
  5. 1 row inserted
  6. SQL>Insert IntoT1Values(4,'Duck');
  7. 1 row inserted
  8. SQL>Commit;
  9. CommitComplete
  10. SQL>
  11. SQL>UpdateT1Set Name='Kate' WhereId = 2;
  12. 1 row updated
  13. SQL>UpdateT1Set Name='Huna' WhereId = 2;
  14. 1 row updated
  15. SQL>Commit;
  16. CommitComplete
  17. SQL>SelectSystimestampFromDual;
  18. SYSTIMESTAMP
  19. --------------------------------------------------------------------------------
  20. 31-DEC-11 03.05.31.071000 PM + 08:00
  21. SQL>
  22. SQL>SELECTVersions_startscn, versions_starttime,
  23. 2 versions_endscn, versions_endtime,
  24. 3 versions_xid, versions_operation,
  25. 4 id,Name
  26. 5FROMHr. t1
  27. 6 VERSIONSBETWEEN TIMESTAMP
  28. 7 TO_TIMESTAMP ('2017-12-31 14:58:26','Yyyy-MM-DD HH24: MI: ss')
  29. 8ANDTO_TIMESTAMP ('2017-12-31 15:05:31','Yyyy-MM-DD HH24: MI: ss');

Brief description:

Row 6: start_scn: 3852006 end_scn: 3852023 operation: I (insert) indicates inserting values (1, 'jash ')

The fifth line: start_scn: 3852023 operation: U (update) indicates that the record with 'bob' id 1 is updated. Therefore, the newly inserted data in Row 6 is updated;

......

......

You can see that the version record of the row of interest can be found through the query, which must exist in the undo rollback segment and commit committed transactions;

Finally, let's take a look at the overview of the official documentation:

Oracle Flashback features use the Automatic Undo Management (AUM) system to obtain metadata and historical data for transactions. they rely on undo data, which are records of the effects of individual transactions. for example, if a user runs an UPDATE statement to change a salary from 1000 to 1100, then Oracle Database stores the value 1000 in the undo data. undo data is persistent and has ves a database shutdown.

By using flashback features, you can use undo data to query past data or recover from logical damage. Besides using it in flashback features, Oracle Database uses undo data to perform these actions:

• Roll back active transactions

• Recover terminated transactions by using database or process recovery

• Provide read consistency for SQL queries

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.