Skip Headers

PL/SQL User's Guide and Reference
10g Release 1 (10.1)

Part Number B10807-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

TIMESTAMP_TO_SCN Function


Syntax
return_value := TIMESTAMP_TO_SCN(timestamp);

Purpose

TIMESTAMP_TO_SCN takes an argument that represents a precise time, and returns the system change number (SCN) of the database at that moment in time. The returned value has the datatype NUMBER.


Usage Notes

This function is part of the flashback query feature. System change numbers provide a precise way to specify the database state at a moment in time, so that you can see the data as it was at that moment.

Call this function to find out the system change number associated with the date and time to which you want to "flash back".


Examples
DECLARE
   right_now TIMESTAMP; yesterday TIMESTAMP; sometime TIMESTAMP;
   scn1 INTEGER; scn2 INTEGER; scn3 INTEGER;
BEGIN
-- Get the current SCN.
   right_now := SYSTIMESTAMP;
   scn1 := TIMESTAMP_TO_SCN(right_now);
   dbms_output.put_line('Current SCN is ' || scn1);

-- Get the SCN from exactly 1 day ago.
   yesterday := right_now - 1;
   scn2 := TIMESTAMP_TO_SCN(yesterday);
   dbms_output.put_line('SCN from yesterday is ' || scn2);

-- Find an arbitrary SCN somewhere between yesterday and today.
-- (In a real program we would have stored the SCN at some significant moment.)
   scn3 := (scn1 + scn2) / 2;
-- Find out what time that SCN was in effect.
   sometime := SCN_TO_TIMESTAMP(scn3);
   dbms_output.put_line('SCN ' || scn3 || ' was in effect at ' || TO_CHAR(sometime));
END;
/

Related Topics

SCN_TO_TIMESTAMP Function