Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How does Oracle give a query a consistent view of data while other transactions update the same rows, without read locks?

Oracle uses multi-version read consistency. Every query is tied to the SCN, the system change number, current when it started; when it reads a block that has changed since then, Oracle rebuilds the older version of that block from undo records. So a query sees only data committed before it began, readers never block writers and writers never block readers, and no read locks are needed.

Why this question is asked

Anyone who has worked with databases that use read locks knows the pain of reports blocking updates and updates blocking reports. Oracle avoids this entirely, and understanding how is useful far beyond Oracle, because PostgreSQL, MySQL InnoDB and SQL Server's snapshot modes use variations of the same idea. Interviewers ask this to check that we know what a query actually sees while others are writing. In this answer, we will recap SCNs and undo, follow one query step by step while another session updates a row, look at isolation levels, and see how undo also powers rollback and flashback queries.

1A Quick Recap of SCNs and Undo

The SCN, system change number, is Oracle's logical clock. Every commit gets a new, higher SCN, and every data block remembers which changes it contains. When a query starts, Oracle notes the current SCN. That number defines the query's view of the world: everything committed at or before it is visible, nothing after it is.

Undo is the other half. Whenever a transaction changes a row, Oracle first writes an undo record describing how to reverse the change, for example the old balance, and stores it in the undo tablespace. Then it changes the row in place in the data block. The block keeps a pointer to the undo records, so the old version can always be reconstructed while the undo is still there.

2Following One Query While Another Session Updates

Let us take two sessions. Session A starts a long query over accounts. While it runs, session B updates an account that A has not reached yet and commits.

Java
-- Session A, starts at SCN 5000
SELECT SUM(balance) FROM accounts; -- still running...
-- Session B, while A runs
UPDATE accounts SET balance = balance - 100 WHERE id = 42; -- 900 -> 800
COMMIT; -- commit SCN 5010
-- Session A reaches the block holding id 42
-- block is newer than SCN 5000 -> apply undo -> balance 900
-- Session A's result includes 900 for id 42, as of SCN 5000
Step throughA query reads the version from its start SCN
Session AData blockUndoSession B
start query at SCN 5000
update id 42: 900 -> 800
old value 900 saved in undo
commit at SCN 5010
read block with id 42
block changed after SCN 5000
fetch undo for id 42
balance was 900

8 messages in order. Play them, or step through them one at a time.

Neither session waits for the other; A rebuilds the old version from undo.

When A reaches the block with account 42, it sees that the block contains a change committed at SCN 5010, which is after its own start SCN 5000. So it makes a private copy of the block in memory, a consistent read copy, and applies the undo record to it, turning 800 back into 900. A's sum is exactly what the table held at SCN 5000, as if the update never happened.

Notice what did not happen. A took no lock that stopped B from updating. B did not wait for A to finish. And A did not wait for B's commit either: if B had not yet committed, A would still rebuild the committed version from undo and carry on.

3Readers and Writers Never Block Each Other

This gives Oracle its well-known rule: readers do not block writers, and writers do not block readers. The only blocking left is writer against writer. If B and another session C both try to update account 42, C waits for B to commit or roll back, because two transactions cannot change the same row at the same time.

For Java code this means a long report running through JDBC does not stop the order service from updating rows, and the order service does not make the report wait. It also means a plain SELECT never protects us from concurrent changes. If our logic reads a balance and then decides to update it, we need SELECT ... FOR UPDATE to lock the row, because the plain read took no lock at all.

4Statement-Level and Transaction-Level Consistency

The isolation level decides which SCN a statement uses. Oracle's default is READ COMMITTED with statement-level consistency: each statement gets its own start SCN. Two SELECTs in the same transaction can therefore see different data, if someone committed in between.

SERIALIZABLE gives transaction-level consistency: every statement in the transaction uses the SCN from the start of the transaction, so the whole transaction sees one frozen picture. If it tries to update a row that another transaction changed and committed after that SCN, Oracle raises ORA-08177, cannot serialize access for this transaction, and the application must retry. Oracle also offers SET TRANSACTION READ ONLY, which gives the same frozen view for reports that do not write.

Java
// Java: transaction-level consistency for a multi-query report
conn.setAutoCommit(false);
conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
long total = sumBalances(conn); // as of the transaction start
long count = countAccounts(conn); // same point in time, so totals agree
conn.commit();
Which SCN a statement sees
IsolationConsistent as ofTypical use
READ COMMITTED (default)Start of each statementOLTP
SERIALIZABLEStart of the transactionLogic needing one picture, with retries
READ ONLY transactionStart of the transactionMulti-query reports

5Undo Also Powers Rollback and Flashback

The same undo records serve two more purposes. When a transaction rolls back, Oracle applies its undo records to restore the old values. And flashback query lets us ask for data as it was at an earlier time, as long as the undo is still available.

SQL
-- Who changed this account in the last 10 minutes? Compare with the old version
SELECT id, balance
FROM accounts AS OF TIMESTAMP SYSTIMESTAMP - INTERVAL '10' MINUTE
WHERE id = 42;
-- 42 900

The limit is how long undo is kept. The UNDO_RETENTION parameter, 900 seconds by default, is a target for how long committed undo stays, and busy systems can overwrite it sooner if the undo tablespace is small. A query that needs undo that has already been overwritten fails with ORA-01555, snapshot too old, which is the price of this design.

6Follow-up questions

How is this different from PostgreSQL's MVCC?

Both give each query a snapshot, but they store old versions differently. Oracle updates rows in place and keeps old versions in undo, rebuilding them on demand. PostgreSQL writes a new row version into the table and leaves the old one as a dead tuple until VACUUM removes it. So Oracle's failure mode is ORA-01555 when undo is gone, and PostgreSQL's is table bloat when cleanup is held back.

Does a SELECT in Oracle ever wait for locks?

A plain SELECT does not. SELECT ... FOR UPDATE does, because it locks the rows it returns and must wait if another transaction holds a lock on them. With FOR UPDATE NOWAIT or WAIT n, we can make it fail immediately or after n seconds instead.

What does an uncommitted change look like to another session?

It is invisible. The other session finds that the row was changed by a transaction that has not committed, and rebuilds the last committed version from undo. Oracle has no dirty reads at any isolation level.

7Conclusion

In this answer, we saw that Oracle gives each query a consistent view by fixing the SCN at which it starts and rebuilding newer blocks to that point from undo records. That is why readers do not block writers and writers do not block readers, with only writer against writer conflicts left. The default READ COMMITTED level is consistent per statement, SERIALIZABLE and READ ONLY are consistent per transaction, and the same undo also serves rollback and flashback queries, as long as it has not been overwritten.

What to say in the interviewAbout 80 seconds aloud

Open with

Oracle uses multi-version read consistency instead of read locks. When a query starts, Oracle records the current SCN, the system change number, and the query sees exactly the data committed as of that SCN.

Then, if they want more

Writers update rows in place, but before changing a row they write an undo record with the old value. So if my query reaches a block that someone changed after my start SCN, Oracle makes a consistent read copy of that block and applies the undo to roll it back to my point in time.

The effect is that readers never block writers and writers never block readers; only two writers on the same row wait for each other. It also means uncommitted data is never visible. The default isolation is READ COMMITTED with statement-level consistency, so each statement gets its own SCN and two queries in one transaction can see different data.

SERIALIZABLE or a read-only transaction fixes the SCN at the start of the transaction, which is what I would use for a multi-query report; in SERIALIZABLE, updating a row someone else changed gives ORA-08177 and a retry. The same undo powers rollback and flashback queries with AS OF TIMESTAMP.

The trade-off is that undo can be overwritten, and a long query then fails with ORA-01555.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How does Oracle give a query a consistent view of data while other transactions update...": https://scrivio-interview-library.netlify.app/databases/oracle-and-sql-server/f1d19d802a/