PL/SQL User's Guide and Reference 10g Release 1 (10.1) Part Number B10807-01 |
|
|
View PDF |
return_value := SCN_TO_TIMESTAMP(number);
SCN_TO_TIMESTAMP
takes an argument that represents a system change number (SCN) and returns the timestamp associated with that SCN. The returned value has the datatype TIMESTAMP
.
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 date and time associated with an SCN that you have stored to use with flashback query.
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; /