1 System Change Number (SCN) This is a sequential counter, identifying precisely a moment in the database.
This is the most accurate way to identify a moment in time.
You can query
SELECT CURRENT_SCN FROM V$DATABASE;
or
SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL, to get the current change number.
the SCN of the most recent change to a given row, that is, the latest COMMIT operation
for the row. For example:
SELECT ora_rowscn, last_name, salary FROM employees
WHERE employee_id = 7788;
ORA_ROWSCN NAME SALARY
---------- ---- ------
202553 Fudd 3000
The latest COMMIT operation for the row took place at approximately SCN 202553.
You can use function SCN_TO_TIMESTAMP to convert an SCN, like ORA_ROWSCN, to the corresponding TIMESTAMP value.
ORA_SCN is in fact a conservative upper bound of the latest commit time: the actual
commit SCN can be somewhat earlier. ORA_SCN is more precise (closer to the actual commit SCN) for a row-dependent table (created using CREATE TABLE with the ROWDEPENDENCIES clause).
Noteworthy uses of ORA_ROWSCN in application development include oncurrency control and client cache invalidation. To see how you might use it in concurrency control, consider the following scenario.
Your application examines a row of data, and records the corresponding ORA_ROWSCN as 202553. Later, the application needs to update the row, but only if its record of the data is still accurate. That is, this particular update operation depends, logically, on the row not having been changed. The operation is therefore made conditional on the ORA_ROWSCN being still 202553. Here is an equivalent interactive command:
UPDATE employees SET salary = salary + 100
WHERE employee_id = 7788 AND ora_rowscn = 202553;
The conditional update fails in this case, because the ORA_ROWSCN is no longer 202553. This means that some user or another application changed the row and performed a COMMIT more recently than the recorded ORA_ROWSCN.
Your application queries again to obtain the new row data and ORA_ROWSCN. Suppose that the ORA_ROWSCN is now 415639. The application tries the conditional update again, using the new ORA_ROWSCN. This time, the update succeeds, and it is committed. Here is an interactive equivalent:
SQL> UPDATE employees SET salary = salary + 100
WHERE empno = 7788 AND ora_rowscn = 415639;
1 row updated.
SQL> COMMIT;
Commit complete.
SQL> SELECT ora_rowscn, name, salary FROM employees WHERE empno = 7788;
ORA_ROWSCN NAME SALARY
---------- ---- ------
465461 Fudd 3100
The SCN corresponding to the new COMMIT is 465461.
It has a precision of +/- 3 seconds
It has a precision of +/- 3 seconds
When you use time based flashback you get the data in a period between +- 5 mn.
DBMS_FLASHBACK.ENABLE_AT_TIME and AS OF TIMESTAMP maps to an SCN value.
As the SCN-time is recorded every X minutes. The time you specify is rounded down by up to X minutes from database startup.
This situation could create the ORA-01466 unable to read data - table definition has changed.
There is only track of times up to a maximum of 5 days (Database up time).
SELECT TO_CHAR(TIME_DP,'DDMONYYYY HH24:MI') DATE_TIME,SCN
FROM SMON_SCN_TIME
Date_time SCN
04MAY2006 16:20 576601
04MAY2006 16:26 576799
04MAY2006 16:30 577003
04MAY2006 16:36 577393
04MAY2006 16:41 577585
04MAY2006 16:46 577790
With this feature, each row in the table has a system change number (SCN) that
represents a time greater than or equal to the commit time of the last transaction that
modified the row. You cannot change this setting after table is created.
ROWDEPENDENCIES Specify ROWDEPENDENCIES if you want to enable row-level dependency tracking. This setting is useful primarily to allow for parallel propagation in replication environments. It increases the size of each row by 6 bytes.
NOROWDEPENDENCIES Specify NOROWDEPENDENCIES if you do not want table to use the row-level dependency tracking feature. This is the default.
If you use row-level dependency tracking you can obtain a more fine-grained approximation of the ORA_ROWSCN in a table.
This is the most accurate way to identify a moment in time.
You can query
SELECT CURRENT_SCN FROM V$DATABASE;
or
SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER FROM DUAL, to get the current change number.
1.1 ORA_ROWSCN
Is a pseudocolumn of any table that is not fixed or external. It representsthe SCN of the most recent change to a given row, that is, the latest COMMIT operation
for the row. For example:
SELECT ora_rowscn, last_name, salary FROM employees
WHERE employee_id = 7788;
ORA_ROWSCN NAME SALARY
---------- ---- ------
202553 Fudd 3000
The latest COMMIT operation for the row took place at approximately SCN 202553.
You can use function SCN_TO_TIMESTAMP to convert an SCN, like ORA_ROWSCN, to the corresponding TIMESTAMP value.
ORA_SCN is in fact a conservative upper bound of the latest commit time: the actual
commit SCN can be somewhat earlier. ORA_SCN is more precise (closer to the actual commit SCN) for a row-dependent table (created using CREATE TABLE with the ROWDEPENDENCIES clause).
Noteworthy uses of ORA_ROWSCN in application development include oncurrency control and client cache invalidation. To see how you might use it in concurrency control, consider the following scenario.
Your application examines a row of data, and records the corresponding ORA_ROWSCN as 202553. Later, the application needs to update the row, but only if its record of the data is still accurate. That is, this particular update operation depends, logically, on the row not having been changed. The operation is therefore made conditional on the ORA_ROWSCN being still 202553. Here is an equivalent interactive command:
UPDATE employees SET salary = salary + 100
WHERE employee_id = 7788 AND ora_rowscn = 202553;
The conditional update fails in this case, because the ORA_ROWSCN is no longer 202553. This means that some user or another application changed the row and performed a COMMIT more recently than the recorded ORA_ROWSCN.
Your application queries again to obtain the new row data and ORA_ROWSCN. Suppose that the ORA_ROWSCN is now 415639. The application tries the conditional update again, using the new ORA_ROWSCN. This time, the update succeeds, and it is committed. Here is an interactive equivalent:
SQL> UPDATE employees SET salary = salary + 100
WHERE empno = 7788 AND ora_rowscn = 415639;
1 row updated.
SQL> COMMIT;
Commit complete.
SQL> SELECT ora_rowscn, name, salary FROM employees WHERE empno = 7788;
ORA_ROWSCN NAME SALARY
---------- ---- ------
465461 Fudd 3100
The SCN corresponding to the new COMMIT is 465461.
1.2 SCN_TO_TIMESTAMP( nSCN NUMBER)
Converts a SCN to TIMESTAMPIt has a precision of +/- 3 seconds
1.3 TIMESTAMP_TO_SCN(dTimestamp)
Converts TIMESTAMP to SCNIt has a precision of +/- 3 seconds
1.4 Table: SMON_SCN_TIME
This table translate time to SCN approximatelyWhen you use time based flashback you get the data in a period between +- 5 mn.
DBMS_FLASHBACK.ENABLE_AT_TIME and AS OF TIMESTAMP maps to an SCN value.
As the SCN-time is recorded every X minutes. The time you specify is rounded down by up to X minutes from database startup.
This situation could create the ORA-01466 unable to read data - table definition has changed.
There is only track of times up to a maximum of 5 days (Database up time).
SELECT TO_CHAR(TIME_DP,'DDMONYYYY HH24:MI') DATE_TIME,SCN
FROM SMON_SCN_TIME
Date_time SCN
04MAY2006 16:20 576601
04MAY2006 16:26 576799
04MAY2006 16:30 577003
04MAY2006 16:36 577393
04MAY2006 16:41 577585
04MAY2006 16:46 577790
1.5 CREATE TABLE ROWDEPENDENCIES | NOROWDEPENDENCIES (default)
This clause in the CREATE TABLE statement lets you specify whether table will use row-level dependency tracking.With this feature, each row in the table has a system change number (SCN) that
represents a time greater than or equal to the commit time of the last transaction that
modified the row. You cannot change this setting after table is created.
ROWDEPENDENCIES Specify ROWDEPENDENCIES if you want to enable row-level dependency tracking. This setting is useful primarily to allow for parallel propagation in replication environments. It increases the size of each row by 6 bytes.
NOROWDEPENDENCIES Specify NOROWDEPENDENCIES if you do not want table to use the row-level dependency tracking feature. This is the default.
If you use row-level dependency tracking you can obtain a more fine-grained approximation of the ORA_ROWSCN in a table.
No comments:
Post a Comment