rowid定义:
每一个表中都有一列rowid(iot表除外),每一行的rowid代表了该行在数据库中存储的实际地址。rowid是伪列(pseudocolumn),伪劣的意思是实际上这一列本身在数据字典中并不存在,在查询结果输出时它被构造出来的。在操作上它和普通的列也有一些差别:不能通过desc以及select直接显示出来,除非显式说明,rowid不能做表的primarykey ,也不能对rowid执行dml操作。
SQL> select rowid ,
substr(rowid ,1,6) data_object_id ,
substr(rowid ,7,3)rfile#,substr(rowid,10,6) block_id,
substr(rowid ,16,3) bject_rowid from GEDB.CMSADMIN
where rownum <2;
ROWID DATA_OBJECT_ID RFILE# BLOCK_ID OBJECT_ID
--------------- ------------ ------ ------------ ------
AAAi8dAAEAAAxi0AAA AAAi8d AAE AAAxi0 AAA
这里显示出来的是64进制数,oracle在设计rowid时用A~Z表示0-25,用a~z表示26-51,用0~9表示52-61,用+表示62,用/表示63。
即:AAAi8d========> A =0 A=0 A=0 i = 34 8 = 60 d= 29
SQL> select34*power(64,2) + 60*64 + 29 from dual ;
34*POWER(64,2)+60*64+29
----------------------
143133
SQL> selectobject_id , data_object_id from dba_objects where object_name='CMSADMIN' andowner='GEDB';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
143133 143133
可以用同样的方法计算 RFILE# ,BLOCK_ID , BJECT_ID
oracle还提供了一个package:dbms_rowid,利用dbms_rowid中的几个函数可以很容易的把rowid拆分成10进制数:
SQL> select dbms_rowid.rowid_object('AAAi8dAAEAAAxi0AAA') objectid ,
dbms_rowid.rowid_relative_fno('AAAi8dAAEAAAxi0AAA') fileno,
dbms_rowid.rowid_block_number('AAAi8dAAEAAAxi0AAA') blockid ,
dbms_rowid.rowid_row_number('AAAi8dAAEAAAxi0AAA') rowno
from dual ;
OBJECTID FILENO BLOCKID ROWNO|
---------- ---------- ---------- ----------
143133 4 202932 0
dbms_row中还有几个非常有用的函数:
参见: http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_rowid.htm
ROWID_TO_ABSOLUTE_FNO(rowid) 可以实现rfile#(相对文件号) 到file#(绝对文件号)的转化。
This functionextracts the absolute file number from a ROWID, where the file number isabsolute for a row in a given schema and table. The schema name and the name ofthe schema object (such as a table name) are provided as IN parametersfor this function.
ROWID_TO_EXTENDED 可以实现从restricted rowid到extended rowid的转化。
This functiontranslates a restricted ROWID that addresses a row in a schema andtable that you specify to the extended ROWID format. Later, it may beremoved from this package into a different place.
ROWID_CREATE 可以实现创建一个rowid
This function lets you create a ROWID, given the component parts as parameters.
This is useful fortesting ROWID operations, because only the Oracle Server can create a validROWID that points to data in a database.
语法:
DBMS_ROWID.ROWID_CREATE(
rowid_type IN NUMBER,
object_number IN NUMBER,
relative_fno IN NUMBER,
block_number IN NUMBER,
row_number IN NUMBER)
RETURN ROWID;
参数的描述:
rowid_type
Type (restricted or extended). Set the rowid_typeparameter to 0 for a restricted ROWID. Set it to 1 to create an extended ROWID.
If you specify rowid_type as 0, then the required object_numberparameter is ignored, and ROWID_CREATE returns a restricted ROWID.
object_number Dataobject number (rowid_object_undefined for restricted).
relative_fno Relative file number.
block_number Block number in this file.
row_number Returns row number in this block.
用这个的作用:
数据块损坏,如果是用户查询某个表报block损坏的时候可以通过block算出具体的行
2)查询被锁定的具体行是会用到,请参考另一个文章:如果查询被锁定的具体行
如何查询被锁的对象请参加:
http://hi.baidu.com/wa0362/blog/item/4e06aa87f732732cc75cc33a.html