Oracle Consulting Oracle Training Oracle Support Development
Home
Catalog
Oracle Books
SQL Server Books
IT Books
Job Interview Books
eBooks
Rampant Horse Books
911 Series
Pedagogue Books

Oracle Software
image
Write for Rampant
Publish with Rampant
Rampant News
Rampant Authors
Rampant Staff
 Phone
 919-335-6342
Oracle News
Oracle Forum
Oracle Tips
Articles by our Authors
Press Releases
SQL Server Books
image
image

Oracle Books

Oracle tuning

Oracle training

Oracle support

Remote Oracle

STATSPACK Viewer

Privacy Policy

 

   
 

Oracle Row Timestamp

 
Oracle Tips by Burleson


Oracle10g Row Timestamp

Oracle Database 10g provided a new pseudo-column, consisting of the committed timestamp or SCN that provides applications and users the ability to efficiently implement optimistic locking. In previous releases, when posting updates to the database, applications had to read in all column values or user-specified indicator columns, compare them with those previously fetched, and update those with identical values. With this feature, only the row SCN needs to be retrieved and compared to verify that the row has not changed from the time of the select to the update.

The pseudo-column for the committed SCN is called ora_rowscn and is one of the version query pseudo-columns.

The ora_rowscn pseudo-column returns, for each version of each row, the system change number (SCN) of the row. You cannot use this pseudo-column in a query to a view.

However, you can use it to refer to the underlying table when creating a view. You can also use this pseudo-column in the WHERE clause of an UPDATE or DELETE statement.

Even though this pseudo-column is grouped with the restricted version query pseudo-columns, this pseudo-column can be used like any other pseudo-column. For example:

SQL> SELECT ora_rowscn FROM used_boats:

ORA_ROWSCN
----------
791744
791744
791744
791744
791744
791744
791744
791744
791744
791744
791744
791744
791744
791744

13 rows selected.

The above query shows us that all of the records in used_boats were committed in the same transaction. Let's update some of the rows and see what happens.

SQL> UPDATE used_boats SET price=price*1.1 WHERE seller_id=1;

3 rows updated.

SQL> commit;

Commit complete

SQL> SELECT ora_rowscn FROM used_boats:

ORA_ROWSCN
----------
816673
816673
816673
791744
791744
791744
791744
791744
791744
791744
791744
791744
791744
791744

13 rows selected.

Another convenient function allows you to retrieve the actual time that the row was last altered through a conversion function called scn_to_timestamp. Let's look at an example usage of this function.

SQL> select scn_to_timestamp(ora_rowscn) from used_boats;


SCN_TO_TIMESTAMP(ORA_ROWSCN)
30-AUG-03 11.06.08.000000000 PM
30-AUG-03 11.06.08.000000000 PM
30-AUG-03 11.06.08.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM
30-AUG-03 04.33.19.000000000 PM

13 rows selected.

The ora_rowscn has the following restrictions: This pseudo-column is not supported for external tables or when directly querying views.

The data from the SCN and timestamp pseudo-columns could prove invaluable in a flashback situation.



 

Download your Oracle scripts now:

www.oracle-script.com

The definitive Oracle Script collection for every Oracle professional DBA

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

   

 Copyright © 1996 -2023 by Burleson. All rights reserved.


Oracle® is the registered trademark of Oracle Corporation. SQL Server® is the registered trademark of Microsoft Corporation. 
Many of the designations used by computer vendors to distinguish their products are claimed as Trademarks