首页 > 数字化转型 > ERP > 使用dbms_rowid包获得rowid的详细信息
参考:http://www.eygle.com/faq/Use.dbms_rowid.Package.Get.Detail.Of.Rowid.htm
Rowid中包含了记录的详细信息,通过dbms_rowid包可以获得这些信息.本文通过一个定义自定义函数介绍该package的使用.
[oracle@linx130 bin]$ cat f_get_rowid.sql
create or replace function get_rowid
(l_rowid in varchar2)
return varchar2
is
ls_my_rowid varchar2(200);
rowid_type number;
object_number number;
relative_fno number;
block_number number;
row_number number;
begin
dbms_rowid.rowid_info(l_rowid,rowid_type,object_number,relative_fno, block_number, row_number);
ls_my_rowid := 'Object# is :'||to_char(object_number)||chr(10)||
'rowid type is :'||to_char(rowid_type)||chr(10)||
'Relative_fno is :'||to_char(relative_fno)||chr(10)||
'Block number is :'||to_char(block_number)||chr(10)||
'Row number is :'||to_char(row_number);
return ls_my_rowid ;
end;
/
下面编译并试用一下:
[oracle@linx130 bin]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Mar 20 08:33:05 2008
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
SQL> @ /oracle/product/10.2.0/bin/f_get_rowid
Function created.
SQL> select rowid,deptno,dname,loc from scott.dept;
ROWID DEPTNO DNAME LOC
------------------ ---------- -------------------- --------------------------
AAAMgxAAEAAAAAQAAA 10 ACCOUNTING NEW YORK
AAAMgxAAEAAAAAQAAB 20 RESEARCH DALLAS
AAAMgxAAEAAAAAQAAC 30 SALES CHICAGO
AAAMgxAAEAAAAAQAAD 40 OPERATIONS BOSTON
SQL> select get_rowid('AAAMgxAAEAAAAAQAAA') from dual;
GET_ROWID('AAAMGXAAEAAAAAQAAA')
--------------------------------------------------------------------------------
Object# is :51249
rowid type is :1
Relative_fno is :4
Block number is :16
Row number is :0
SQL> select get_rowid('AAAMgxAAEAAAAAQAAB') from dual;
GET_ROWID('AAAMGXAAEAAAAAQAAB')
--------------------------------------------------------------------------------
Object# is :51249
rowid type is :1
Relative_fno is :4
Block number is :16
Row number is :1
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/271283/viewspace-1001225/ ,如需转载,请注明出处,否则将追究法律责任。