|
|
|
|
|
|
|
Re: ORA_ROWSCN and SCN_TO_TIMESTAMP - in Toad [message #598353 is a reply to message #598343] |
Mon, 14 October 2013 04:08 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
I'm not sure I agree with the documentation's statement that Quote:This pseudocolumn is useful for determining approximately when a row was last updated.
Granted it then clarifies
Quote:It is not absolutely precise, because Oracle tracks SCNs by transaction committed for the block in which the row resides. But it is that very clarification that makes the first statement completely invalid. We can easily have a number of rows that appear to have been changed very recently, that have in fact not been changed since they were first inserted many moons ago.
--Without going into detail on the structure of a rowid, in the exmple below, the block in which a row is located can be identified by characters 10 to 15. So we can see that we have rows located in two separate blocks.
SQL> select employee_id, ora_rowscn, rowid
2 from employees
3 where employee_id in (100, 101, 102, 103, 104, 198, 199, 200, 201);
EMPLOYEE_ID ORA_ROWSCN ROWID
----------- ---------- ------------------
100 5069516 AAAR5kAAFAAAADNAAA
101 5069516 AAAR5kAAFAAAADNAAB
102 5069516 AAAR5kAAFAAAADNAAC
103 5069516 AAAR5kAAFAAAADNAAD
104 5069516 AAAR5kAAFAAAADNAAE
198 948777 AAAR5kAAFAAAADOAAA
199 948777 AAAR5kAAFAAAADOAAB
200 948777 AAAR5kAAFAAAADOAAC
201 948777 AAAR5kAAFAAAADOAAD
9 rows selected.
--Let's update just one row in the table.
SQL>
SQL> update employees
2 set salary = salary
3 where employee_id = 100;
1 row updated.
SQL>
SQL> commit;
Commit complete.
--Note the ora_rowscn changes for ALL of the rows in the block that holds the row that was updated.
SQL>
SQL> select employee_id, ora_rowscn, rowid
2 from employees
3 where employee_id in (100, 101, 102, 103, 104, 198, 199, 200, 201);
EMPLOYEE_ID ORA_ROWSCN ROWID
----------- ---------- ------------------
100 5069623 AAAR5kAAFAAAADNAAA
101 5069623 AAAR5kAAFAAAADNAAB
102 5069623 AAAR5kAAFAAAADNAAC
103 5069623 AAAR5kAAFAAAADNAAD
104 5069623 AAAR5kAAFAAAADNAAE
198 948777 AAAR5kAAFAAAADOAAA
199 948777 AAAR5kAAFAAAADOAAB
200 948777 AAAR5kAAFAAAADOAAC
201 948777 AAAR5kAAFAAAADOAAD
9 rows selected.
--Let's update a row in the 'other' block.
SQL> update employees
2 set salary = salary
3 where employee_id = 201;
1 row updated.
SQL> commit;
Commit complete.
--Again, ALL rows change their ora_rowscn value.
SQL> select employee_id, ora_rowscn, rowid
2 from employees
3 where employee_id in (100, 101, 102, 103, 104, 198, 199, 200, 201);
EMPLOYEE_ID ORA_ROWSCN ROWID
----------- ---------- ------------------
100 5069623 AAAR5kAAFAAAADNAAA
101 5069623 AAAR5kAAFAAAADNAAB
102 5069623 AAAR5kAAFAAAADNAAC
103 5069623 AAAR5kAAFAAAADNAAD
104 5069623 AAAR5kAAFAAAADNAAE
198 5069639 AAAR5kAAFAAAADOAAA
199 5069639 AAAR5kAAFAAAADOAAB
200 5069639 AAAR5kAAFAAAADOAAC
201 5069639 AAAR5kAAFAAAADOAAD
9 rows selected.
|
|
|