|PL/SQL User's Guide and Reference
10g Release 1 (10.1)
Part Number B10807-01
return_value := TIMESTAMP_TO_SCN(timestamp);
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
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".
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; /