Chapter 16 · Flashback Technologies, Recycle Bin, Data Archive, and Recovery Without Restore

Flashback Query with AS OF SCN/TIMESTAMP and Undo-Dependent Historical Reads

Recover the past as a queryable consistent image with AS OF SCN/TIMESTAMP, while separating SCN↔time mapping from the shorter undo history that actually makes historical row reconstruction possible.

Advanced115–135 minutesUndo-backed historical-read labOracle AI Database 26ai · RU 23.26.3 baselineFree-compatible · exact SCN preferred for critical repairLast reviewed: August 2026

Learning outcomes

A ServiceHub operator accidentally changes a work order from OPEN to CLOSED and commits. The row is not “uncommitted,” so a normal ROLLBACK cannot help. If Oracle still retains the required undo, Flashback Query can read a past committed image of the row without restoring a backup or changing the current table. That ability is powerful precisely because it is temporary: the history depends on undo availability.

01

Use SELECT ... AS OF SCN and AS OF TIMESTAMP to read a past consistent image without changing current data.

02

Explain System Change Number (SCN) ordering and the approximate SCN↔timestamp mapping.

03

Separate the lifetime of SCN/time mapping metadata from the lifetime of undo needed to reconstruct table blocks.

04

Diagnose ORA-01555 and other old-snapshot failures without destructively exhausting undo in the mandatory lab.

05

Repair a committed mistake by selecting verified historical values into a controlled current-state DML operation.

Generation-time baseline, feature matrix, and safety boundary

Mandatory examples target Oracle AI Database Free 26ai, reviewed against RU 23.26.3, SQL Developer 26.2, and SQLcl 26.2.1. Free is limited to 2 foreground CPU cores, 2 GB combined SGA/PGA RAM, 12 GB user data, and one installation per logical environment; it receives no Oracle patches or Support service requests. The course CDB/PDB baseline is FREE/FREEPDB1. Basic Flashback Query/Version Query and Flashback Table/Database paths are used locally where safe. The current 26ai licensing matrix marks Flashback Transaction Query and Flashback Transaction unavailable in Free, so those are entitlement-gated extensions rather than mandatory Free commands. No flashback feature is presented as a substitute for RMAN backups and restore drills from Chapter 15.

1. Flashback Query asks the SQL engine to reconstruct an older committed snapshot

AS OF SCN or AS OF TIMESTAMP attaches a historical snapshot to a table reference. Oracle uses Automatic Undo Management (AUM) to reconstruct blocks as they existed at that System Change Number. The query is read-only with respect to the historical image: it does not “rewind” the current table.

sql · current container and undo baseline
SELECT  SYS_CONTEXT('USERENV','CON_NAME') AS con_name,  SYS_CONTEXT('USERENV','CON_ID') AS con_idFROM dual;SELECT name,valueFROM v$parameterWHERE name IN ('undo_management','undo_retention')ORDER BY name;

Run the application lab in FREEPDB1. A non-owner querying another schema's history needs FLASHBACK plus READ/SELECT on that object, or the broader FLASHBACK ANY TABLE privilege.

2. Reproducible ServiceHub setup and exact-SCN capture

sql · setup in FREEPDB1 as the course owner
BEGIN  EXECUTE IMMEDIATE 'DROP TABLE servicehub_flash_case PURGE';EXCEPTION  WHEN OTHERS THEN    IF SQLCODE != -942 THEN RAISE; END IF;END;/CREATE TABLE servicehub_flash_case (  case_id      NUMBER PRIMARY KEY,  status_code  VARCHAR2(12) NOT NULL,  amount       NUMBER(10,2) NOT NULL);INSERT INTO servicehub_flash_case VALUES (1,'OPEN',125.00);COMMIT;VARIABLE good_scn NUMBERBEGIN  :good_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER;END;/PRINT good_scn

The saved SCN is the logical ordering point immediately after the known-good commit. SCN is preferable to a timestamp when an exact recovery boundary matters.

3. Commit the bad change, then compare current and historical images

sql · simulate a committed operator error
UPDATE servicehub_flash_caseSET status_code='CLOSED',    amount=9999WHERE case_id=1;COMMIT;SELECT case_id,status_code,amountFROM servicehub_flash_caseWHERE case_id=1;-- 1 | CLOSED | 9999
sql · read the row as of the saved SCN
SELECT case_id,status_code,amountFROM servicehub_flash_case AS OF SCN :good_scnWHERE case_id=1;-- Expected while undo is available:-- 1 | OPEN | 125

The historical query does not acquire a second “old table.” Oracle reconstructs the needed consistent-read version from current blocks plus undo history.

4. Timestamp flashback maps time to an approximate SCN

Oracle remembers SCN-to-time associations for a limited period. SCN_TO_TIMESTAMP returns an approximate timestamp, typically with about three-second precision. The mapping is retained for at least 120 hours and potentially longer based on tuned undo retention and Flashback Time Travel retention.

sql · convert the exact saved SCN to an approximate timestamp
SELECT  :good_scn AS good_scn,  SCN_TO_TIMESTAMP(:good_scn) AS approximate_timeFROM dual;
sql · timestamp-based form
SELECT case_id,status_code,amountFROM servicehub_flash_caseAS OF TIMESTAMP SCN_TO_TIMESTAMP(:good_scn)WHERE case_id=1;

Do not confuse “Oracle can still map this old SCN to a timestamp” with “Oracle still has the undo needed to reconstruct this table.” The mapping metadata can outlive the actual row-history undo.

5. Undo availability is the hard boundary

sql · observe achieved undo retention and snapshot-too-old evidence
SELECT *FROM (  SELECT    begin_time,    end_time,    tuned_undoretention,    maxquerylen,    ssolderrcnt,    nospaceerrcnt,    undoblks  FROM v$undostat  ORDER BY end_time DESC)FETCH FIRST 12 ROWS ONLY;

TUNED_UNDORETENTION is evidence of what Oracle estimates it can currently retain. SSOLDERRCNT records ORA-01555 occurrences. The configured UNDO_RETENTION is normally a target, not a guarantee unless the undo tablespace uses retention guarantee.

6. Deliberately wrong: “AS OF” means history exists forever

sql · this eventually fails if the required undo has aged out
SELECT case_id,status_code,amountFROM servicehub_flash_case AS OF SCN :very_old_scnWHERE case_id=1;-- Typical failure after required undo was overwritten:-- ORA-01555: snapshot too old ...

ORA-01555 means the rollback/undo records needed by the reader were overwritten by other writers. Do not manufacture the failure by shrinking undo or generating uncontrolled churn on a shared system. In a dedicated test environment you can observe it naturally; in production, diagnose undo generation, space, tuned retention, long-query duration, and retention requirements.

Different old-time failure

A timestamp can also be too old for Oracle's SCN/time mapping, producing a mapping-related error such as ORA-08180. That is a different mechanism from ORA-01555, which means the data reconstruction undo was lost.

7. Use historical data to repair current state explicitly

When only a few rows are wrong, querying the old image and applying a controlled current DML can be safer than rewinding the entire table. Verify the candidate row set first, preserve an audit trail, and let constraints/triggers operate according to the current schema.

sql · repair one row from the verified historical image
MERGE INTO servicehub_flash_case curUSING (  SELECT case_id,status_code,amount  FROM servicehub_flash_case AS OF SCN :good_scn  WHERE case_id=1) oldON (cur.case_id=old.case_id)WHEN MATCHED THEN UPDATE SET  cur.status_code=old.status_code,  cur.amount=old.amount;SELECT case_id,status_code,amountFROM servicehub_flash_caseWHERE case_id=1;-- OPEN | 125ROLLBACK;

The ROLLBACK keeps the lesson non-destructive after proving the repair shape. In an incident, commit only after business/constraint verification.

8. Cleanup

sql · cleanup
DROP TABLE servicehub_flash_case PURGE;

9. Production judgment

Use Flashback Query for investigation, comparison, selective recovery, and historical reporting inside the retained window. Capture exact SCNs around risky changes when possible. Monitor undo space, tuned retention, long queries, and ORA-01555 counts. Flashback Query does not protect against lost datafiles, destroyed undo, lost database hosts, or retention windows shorter than the incident discovery time.

No restart, pack, or special COMPATIBLE change is required for ordinary Flashback Query in the 26ai baseline. Lesson 2 extends one historical image into a row-version timeline and then separates Free Version Query from the more privileged/licensed Flashback Transaction Query.

Check your understanding

  1. What does AS OF SCN change: current data or the query snapshot?
  2. Why is SCN preferred over timestamp for an exact recovery boundary?
  3. Does SCN_TO_TIMESTAMP availability prove the table's historical row image is still reconstructable?
  4. What does ORA-01555 mean in a Flashback Query?
  5. Why is Flashback Query not a backup?
Review the answers

It changes only the snapshot used by that query; current table data is not rewound.

Timestamp-to-SCN mapping is approximate, usually around three-second precision, while a saved SCN is the exact logical point.

No. Mapping metadata can remain even after the undo needed for row reconstruction has been overwritten.

Undo records required for the historical consistent read were overwritten before the query could use them.

It depends on online undo/history and the current database; it does not survive arbitrary media/database loss like independently stored tested backups.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.