Oracle provides the function TIMESTAMP_TO_SCN to determine the database SCN number for a given time. This is very useful in performing multiple Oracle Administrative tasks. This procedure explains the use of this function to extract SCN.
1. Logon to Oracle Database server as the Oracle software owner and start SQLPLUS.
[root@linux2 etc]# su – oracle
Last login: Thu Jun 1 09:25:23 EST 2017 on pts/1
[oracle@linux2 ~]$
[oracle@linux2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 1 13:47:01 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL>
2. Determine Oracle SCN one hour ago by specifying sysdate-1/24
SQL> select timestamp_to_scn(sysdate-1/24) from dual;
TIMESTAMP_TO_SCN(SYSDATE-1/24)
——————————
5062307
SQL>
3. Determine Oracle SCN 1 day ago by specifying sysdate-1
SQL> select timestamp_to_scn(sysdate-1) from dual;
TIMESTAMP_TO_SCN(SYSDATE-1)
—————————
4975332
SQL>
4. Determine Oracle SCN 1 week ago by specifying sysdate-7
SQL> select timestamp_to_scn(sysdate-7) from dual;
TIMESTAMP_TO_SCN(SYSDATE-7)
—————————
4696226
SQL>
5. Determine Oracle SCN by specific date time by using the to_date() function with appropriate date mask.
SQL> select timestamp_to_scn(to_date(’25-MAY-2017 06:30:00′,’DD-MON-YYYY HH24:MI_SS’)) from dual;
TIMESTAMP_TO_SCN(TO_DATE(’25-MAY-201706:30:00′,’DD-MON-YYYYHH24:MI_SS’))
————————————————————————
4696226
SQL>
6. This completes the use of the function TIMESTAMP_TO_SCN.
Larry Catt
OCP