学无止境
分类: Oracle
2010-09-26 15:34:23
目标
------------
对于每一行,ORA_ROWSCN是一个保守的最后提交时间的上限值。该伪列用于决定行最后更新的大致时间。它并不是完全精确的,因为Oracle跟踪SCN是通过事务提交时行所在块的信息。可以创建一个更精细接近SCN的表,表根据row-level依赖跟踪。下面的例子对比了行依赖和非行依赖的表中ORA_ROWSCN的不同:
转载请注明来源于九鼎新创-地面进攻的博客eagle198699.cublog.cn
解答
-------------
为了每行都有一个唯一的ORA_ROWSCN(需要使用行依赖),每个单条DML之后就提交一次。如果多行的操作在一个事务中进行,所有行就都是相同的ORA_ROWSCN。查看下面这个例子:
select ename, ora_rowscn from temp;
ENAME ORA_ROWSCN
---------- ----------
SMITH 1472829
ALLEN 1472832
WARD 1472835
JONES 1472838
MARTIN 1472841
BLAKE 1472850
CLARK 1472853
SCOTT 1472698
KING 1472856
TURNER 1472859
ADAMS 1472862
ENAME ORA_ROWSCN
---------- ----------
JAMES 1472865
FORD 1472868
MILLER 1472871
SQL> insert into temp select * from emp where empno = 7788;
SQL> select ename, ora_rowscn from temp;
ENAME ORA_ROWSCN
---------- ----------
SMITH 1472829
ALLEN 1472832
WARD 1472835
JONES 1472838
MARTIN 1472841
BLAKE 1472850
CLARK 1472853
SCOTT 1472698
KING 1472856
TURNER 1472859
ADAMS 1472862
ENAME ORA_ROWSCN
---------- ----------
JAMES 1472865
FORD 1472868
MILLER 1472871
SCOTT 1473294 <<< 新的ORA_ROWSCN
SQL> insert into temp select * from emp where empno = 7788;
1 row created.
SQL> insert into temp select * from emp where empno = 7788;
1 row created.
SQL> insert into temp select * from emp where empno = 7788;
1 row created.
SQL> commit;
Commit complete.
SQL> select ename, ora_rowscn from temp;
ENAME ORA_ROWSCN
---------- ----------
SMITH 1472829
ALLEN 1472832
WARD 1472835
JONES 1472838
MARTIN 1472841
BLAKE 1472850
CLARK 1472853
SCOTT 1472698
KING 1472856
TURNER 1472859
ADAMS 1472862
ENAME ORA_ROWSCN
---------- ----------
JAMES 1472865
FORD 1472868
MILLER 1472871
SCOTT 1473294
SCOTT 1473314 <<
SCOTT 1473314 << 这3行具有相同的ORA_ROWSCN
SCOTT 1473314 <<
由上可见,在ROWDEPENDENCIES的表中,多行具有相同的ORA_ROWSCN,唯一的可能就是多行在同一个事务中改变并提交。
如果使用NOROWDEPENDENCIES创建的表,所有在同一个BLOCK中的行都具有相同的ORA_ROWSCN。
SQL> select ename, ora_rowscn,rowid from test;
ENAME ORA_ROWSCN ROWID
---------- ---------- ------------------
SMITH 17445533 AAASMWAAEAAAAA8AAA
ALLEN 17445533 AAASMWAAEAAAAA8AAB
WARD 17445533 AAASMWAAEAAAAA8AAC
JONES 17445533 AAASMWAAEAAAAA8AAD
MARTIN 17445533 AAASMWAAEAAAAA8AAE
BLAKE 17445533 AAASMWAAEAAAAA8AAF
CLARK 17445533 AAASMWAAEAAAAA8AAG
SCOTT 17445533 AAASMWAAEAAAAA8AAH
KING 17445533 AAASMWAAEAAAAA8AAI
TURNER 17445533 AAASMWAAEAAAAA8AAJ
ADAMS 17445533 AAASMWAAEAAAAA8AAK
JAMES 17445533 AAASMWAAEAAAAA8AAL
FORD 17445533 AAASMWAAEAAAAA8AAM
MILLER 17445533 AAASMWAAEAAAAA8AAN
SCOTT 17445627 AAASMWAAEAAAAA+AAA
SCOTT 17445627 AAASMWAAEAAAAA+AAB
SCOTT 17445627 AAASMWAAEAAAAA+AAC
SCOTT 17445627 AAASMWAAEAAAAA+AAD
SCOTT 17445627 AAASMWAAEAAAAA+AAE
19 rows selected.
SQL> update test set sal=5000 where ename='WARD';
1 row updated.
SQL> select ename, ora_rowscn,rowid from test;
ENAME ORA_ROWSCN ROWID
---------- ---------- ------------------
SMITH 17445533 AAASMWAAEAAAAA8AAA
ALLEN 17445533 AAASMWAAEAAAAA8AAB
WARD 17445533 AAASMWAAEAAAAA8AAC
JONES 17445533 AAASMWAAEAAAAA8AAD
MARTIN 17445533 AAASMWAAEAAAAA8AAE
BLAKE 17445533 AAASMWAAEAAAAA8AAF
CLARK 17445533 AAASMWAAEAAAAA8AAG
SCOTT 17445533 AAASMWAAEAAAAA8AAH
KING 17445533 AAASMWAAEAAAAA8AAI
TURNER 17445533 AAASMWAAEAAAAA8AAJ
ADAMS 17445533 AAASMWAAEAAAAA8AAK
ENAME ORA_ROWSCN ROWID
---------- ---------- ------------------
JAMES 17445533 AAASMWAAEAAAAA8AAL
FORD 17445533 AAASMWAAEAAAAA8AAM
MILLER 17445533 AAASMWAAEAAAAA8AAN
SCOTT 17445627 AAASMWAAEAAAAA+AAA
SCOTT 17445627 AAASMWAAEAAAAA+AAB
SCOTT 17445627 AAASMWAAEAAAAA+AAC
SCOTT 17445627 AAASMWAAEAAAAA+AAD
SCOTT 17445627 AAASMWAAEAAAAA+AAE
19 rows selected.
SQL> commit;
Commit complete.
SQL> select ename, ora_rowscn,rowid from test;
ENAME ORA_ROWSCN ROWID
---------- ---------- ------------------
SMITH 17445699 AAASMWAAEAAAAA8AAA
ALLEN 17445699 AAASMWAAEAAAAA8AAB
WARD 17445699 AAASMWAAEAAAAA8AAC
JONES 17445699 AAASMWAAEAAAAA8AAD
MARTIN 17445699 AAASMWAAEAAAAA8AAE
BLAKE 17445699 AAASMWAAEAAAAA8AAF
CLARK 17445699 AAASMWAAEAAAAA8AAG
SCOTT 17445699 AAASMWAAEAAAAA8AAH
KING 17445699 AAASMWAAEAAAAA8AAI
TURNER 17445699 AAASMWAAEAAAAA8AAJ
ADAMS 17445699 AAASMWAAEAAAAA8AAK
JAMES 17445699 AAASMWAAEAAAAA8AAL
FORD 17445699 AAASMWAAEAAAAA8AAM
MILLER 17445699 AAASMWAAEAAAAA8AAN
SCOTT 17445627 AAASMWAAEAAAAA+AAA }
SCOTT 17445627 AAASMWAAEAAAAA+AAB }
SCOTT 17445627 AAASMWAAEAAAAA+AAC } 第二个块
SCOTT 17445627 AAASMWAAEAAAAA+AAD }
SCOTT 17445627 AAASMWAAEAAAAA+AAE }
19 rows selected.
在第一个块中所有行的ORA_ROWSCN都被更新了。
chinaunix网友2010-09-27 10:45:27
很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com