对于Oracle中的堆表,我们可以通过oracle内置的ROWID伪列得到对应行记录所在的ROWID的值(注意,这个ROWID只是一个伪列,实际的块中并不存在该列)。然后我们可以通过DBMS_ROWID包中的相关方法来通过ROWID伪列来定位对应数据行的实际物理存储物理地址。
dbms_rowid.rowid_relative_fno:定位该数据行所在的数据文件
dbms_rowid.rowid_block_number:定位该数据行在数据文件的第多少个块
dbms_rowid.rowid_row_number:定位该数据行在数据块的第多少行
下面举例进行查看:
SCOTT@userdata>desc emp Name Null? Type --------------------------------- -------- ---------------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2) SCOTT@userdata>column LOCATION format a20 SCOTT@userdata>select ename,sal,rowid,dbms_rowid.rowid_relative_fno(rowid) || '_' ||dbms_rowid.rowid_block_number(rowid) || '_' || dbms_rowid.rowid_row_number(rowid) location from emp; ENAME SAL ROWID LOCATION ------------------------------ ---------- --------------------- -------------------- SMITH 800 AAAMfPAAEAAAAAgAAA 4_32_0 ALLEN 1600 AAAMfPAAEAAAAAgAAB 4_32_1 WARD 1250 AAAMfPAAEAAAAAgAAC 4_32_2 JONES 2975 AAAMfPAAEAAAAAgAAD 4_32_3 MARTIN 1250 AAAMfPAAEAAAAAgAAE 4_32_4 BLAKE 2850 AAAMfPAAEAAAAAgAAF 4_32_5 CLARK 2450 AAAMfPAAEAAAAAgAAG 4_32_6 SCOTT 3000 AAAMfPAAEAAAAAgAAH 4_32_7 KING 5000 AAAMfPAAEAAAAAgAAI 4_32_8 TURNER 1500 AAAMfPAAEAAAAAgAAJ 4_32_9 ADAMS 1100 AAAMfPAAEAAAAAgAAK 4_32_10 JAMES 950 AAAMfPAAEAAAAAgAAL 4_32_11 FORD 3000 AAAMfPAAEAAAAAgAAM 4_32_12 MILLER 1300 AAAMfPAAEAAAAAgAAN 4_32_13 14 rows selected.
拿第一行数据进行说明该行的ROWID伪列的值为 AAAMfMAAEAAAAAgAAA,可以通过ROWID包通过这个ROWID伪列转换出来的值为4_32_0,代表该行在数据文件4的第32个数据块的第0行。
===================来自一泽涟漪的博客,转载请标明出处 www.cnblogs.com/ilifeilong===================