Using the Oracle SCN keep track of modified rows

Ueli Hofstetter

Can I rely on the Oracle SCN to keep track of modified rows in my database? The goal is to query the database every x minutes for all the rows which have been modified in a particular table. The idea was to remember the current SCN using

SELECT current_scn FROM V$DATABASE;

And then after x minutes I would just run a query like

SELECT * from mytable where ORA_ROWSCN > current_scn_x_minutes_ago;

to get all the rows which have changed since then (and thus have a higher SCN). I am aware that the query will return too many results as the SCNs are managed per block but this does not matter. The main question I have is whether the SCN is strictly increasing, i.e. whether the next generated SCN is always higher than the current SCN (as queried from V$DATABASE) or whether I have to rely on SCN_TO_TIMESTAMP function to be sure that the ordering is correct.

krokodilko

The main question I have is whether the SCN is strictly increasing, i.e. whether the next generated SCN is always higher than the current SCN

According to the documentation: ORA_ROWSCN Pseudocolumn

Whether at the block level or at the row level, the ORA_ROWSCN should not be considered to be an exact SCN. For example, if a transaction changed row R in a block and committed at SCN 10, it is not always true that the ORA_ROWSCN for the row would return 10. While a value less than 10 would never be returned, any value greater than or equal to 10 could be returned. That is, the ORA_ROWSCN of a row is not always guaranteed to be the exact commit SCN of the transaction that last modified that row. However, with fine-grained ORA_ROWSCN, if two transactions T1 and T2 modified the same row R, one after another, and committed, a query on the ORA_ROWSCN of row R after the commit of T1 will return a value lower than the value returned after the commit of T2.

If a block is queried twice, then it is possible for the value of ORA_ROWSCN to change between the queries even though rows have not been updated in the time between the queries. The only guarantee is that the value of ORA_ROWSCN in both queries is greater than the commit SCN of the transaction that last modified that row.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Iterate through rows in pandas dateframe in a cleaner way using .iterrows() and keep track of rows inbetween specific values

Using Handler to keep track of files

How scn map to timestamp using sys.smon_scn_time in Oracle?

Using a Hashmap to keep track of original count or not

How to keep track of established connections using WebSockets

using retain to keep track of maximum value

Using metaclass to keep track of instances in python

How to keep track of dynamic indices of ArrayList of view rows

Oracle SQL unpivot and keep rows with null values

Keep track of variables within class when using method multiple times

Keep track of answers in Parallelized loops using pool() - Python

Read a file using Stream and keep track of the current index

How to keep track of dynamically added nodes using MutationObserver?

How to keep track of webpages opened in web-browser using Python?

what is the logic of using an array to keep track of multiple setTimeouts

Python, using dictionaries and sets to keep track of all occurences of a word

How do I keep track of nodes in a tree using hash table?

Using xsl:accumulator to keep track of text nodes between two PIs

Using closure to keep track of the state of previous function call

How to keep track of mouse events and position using selenium and javascript in python?

MySQL : How to keep track of change in value using its trend?

How do you keep track of changes in registry using powershell?

Keep track of original variable name after rename using notes stata

How to keep track of the user searched items by using cookies

JProgressBar to keep track of a Native(C++) application using JNI

Keep track of pypi dependencies - who is using my packages

How to keep track of page refreshes using PHP and MySQL

How to keep track of users by identifier using Node.JS

PostgreSQL - How to keep track of time since a condition was true using LAG()?