从Oracle 10g开始,如果在表级别打开ROW DEPENDENCIES,业务数据行发生更改时会在数据块中进行登记。
可以通过DUMP数据块来观察上述SCN:
(1)创建测试表,插入3条测试数据,插入一条提交一次。并调用DBMS_ROWID获取3条测试数据的数据文件和数据块,可以看到这3条数据都处在同一个数据块中,如下所示:
SQL> create table test (a number) rowdependencies;
Table created.
SQL> insert into test values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> insert into test values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> insert into test values(3);
1 row created.
SQL> commit;
Commit complete.
SQL> select dbms_rowid.ROWID_RELATIVE_FNO(rowid) file#,
2 dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block#
3 from test;
FILE# BLOCK#
4 37772
4 37772
4 37772
(2)DUMP数据块,如下所示:
SQL> alter system dump datafile 4 block 37772;
System altered.
(3)观察跟踪文件,"scn"表示数据块改变时的SCN,"Scn/Fsc"表示事务槽SCN,"dscn"表示数据行的SCN,如下所示:
scn: 0x0000.000b3bf3 seq: 0x01 flg: 0x06 tail: 0x3bf30601
frmt: 0x02 chkval: 0xb339 type: 0x06=trans data
。。。。。。
Block header dump: 0x0100938c
Object id on Block? Y
seg/obj: 0xcad7 csc: 0x00.b3bf1 itc: 2 flg: E typ: 1 - DATA
brn: 0 bdba: 0x1009389 ver: 0x01 opc: 0
inc: 0 exflg: 0
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x0002.021.0000011c 0x008000bb.010f.16 --U- 1 fsc 0x0000.000b3bf3
0x02 0x0001.02d.00000110 0x0080ba04.00ad.04 C--- 0 scn 0x0000.000b3bef
data_block_dump,data header at 0xd0da664
tsiz: 0x1f98
hsiz: 0x18
pbl: 0x0d0da664
bdba: 0x0100938c
76543210
flag=--R-----
ntab=1
nrow=3
frre=-1
fsbo=0x18
fseo=0x1f74
avsp=0x1f53
tosp=0x1f53
0xe:pti[0] nrow=3 offs=0
0x12:pri[0] offs=0x1f8c
0x14:pri[1] offs=0x1f80
0x16:pri[2] offs=0x1f74
block_row_dump:
tab 0, row 0, @0x1f8c
tl: 12 fb: --H-FL-- lb: 0x0 cc: 1
dscn 0x0000.000b3bd0
col 0: [ 2] c1 02
tab 0, row 1, @0x1f80
tl: 12 fb: --H-FL-- lb: 0x0 cc: 1
dscn 0x0000.000b3bef
col 0: [ 2] c1 03
tab 0, row 2, @0x1f74
tl: 12 fb: --H-FL-- lb: 0x1 cc: 1
dscn 0x0000.00000000
col 0: [ 2] c1 04
end_of_block_dump
End dump data blocks tsn: 4 file#: 4 minblk 37772 maxblk 37772
从Oracle 10g开始,Oracle提供了一个伪列ORA_ROWSCN用于查看数据行改变时的SCN,如下所示:
SQL> select a,ora_rowscn from test;
A ORA_ROWSCN
1 736208
2 736239
3 736243