System Change Number (SCN) in Oracle Database
What is an SCN in Oracle?
A system change number (SCN) is a logical, internal time stamp used by Oracle Database. SCNs order events that occur within the database, which is necessary to satisfy the ACID properties of a transaction
Following are the way to check current SCN in Oracle Database:
1. Fetch the current SCN number in v$database view.
Select CURRENT_SCN from v$database;
SQL> Select CURRENT_SCN from v$database;
CURRENT_SCN
-----------
3208446
2. Get from flashback package.
select dbms_flashback.get_system_change_number from dual;
SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
3208460
3. Get the SCN from timestamp_to_scn function.
select timestamp_to_scn(sysdate) from dual;
SQL> select timestamp_to_scn(sysdate) from dual;
TIMESTAMP_TO_SCN(SYSDATE)
-------------------------
3208486
Example of TIMESTAMP_TO_SCN & SCN_TO_TIMESTAMP function
Select sysdate, timestamp_to_scn(sysdate) from dual;
SYSDATE TIMESTAMP_TO_SCN(SYSDATE)
——————- ————————-
02-04-2019 15:25:05 3408525
Select scn_to_timestamp(3408525) from dual;
SCN_TO_TIMESTAMP(3208525)
—————————————————————————
02-APR-19 03.25.03.000000000 PM
select timestamp_to_scn(to_timestamp('02-04-2019 15:25:05','DD-MM-YYYY HH24:MI:SS')) "SCN" from dual;
SCN
----------
3408525