Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4008476
  • 博文数量: 536
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4825
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(536)

文章存档

2024年(3)

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(252)

2006年(73)

分类: Oracle

2007-08-11 16:12:45

A rowid is a pseudo column (like versions_xid), that uniquely identifies a row within a table, but not within a database. It is possible for two rows of two different tables stored in the same cluster to have the same rowid.

set serveroutput on size 1000000 format wrapped

create table rowid_test (
  id number,
  dummy1 varchar2(4000),
  dummy2 varchar2(4000),
  dummy3 varchar2(4000),
  dummy4 varchar2(4000)
);

begin
  for i in 1 .. 400 loop
    insert into rowid_test values(i,
      lpad('1', i, '1'),
      lpad('2', i, '2'),
      lpad('3', i, '3'),
      lpad('4', i, '4'));
  end loop;
 
  -- delete but every 20th record

  delete from rowid_test where mod(id,20) <> 0;
end;
/

declare
  r rowid;
  i number := 1;
  v_file_name dba_data_files.file_name%type;
begin
  for p in (select rowid from rowid_test) loop
     select file_name into v_file_name
       from dba_data_files
       where file_id = dbms_rowid.rowid_to_absolute_fno(p.rowid, user, 'ROWID_TEST');

     dbms_output.put_line('row no : ' || i );
     dbms_output.put_line(' file : ' || v_file_name);
     dbms_output.put_line(' block no: ' || dbms_rowid.rowid_block_number(p.rowid));
     dbms_output.put_line(' slot no : ' || dbms_rowid.rowid_row_number(p.rowid));
     dbms_output.put_line('');

    i := i+1;
  end loop;
end;
/

drop table rowid_test;



运行的部分结果:
row no    : 1
  file    : D:\ORACLE9I\ORADATA\ORA09\SYSTEM01.DBF
  block no: 83634
  slot no : 19

row no    : 2
  file    : D:\ORACLE9I\ORADATA\ORA09\SYSTEM01.DBF
  block no: 83635
  slot no : 1

row no    : 3
  file    : D:\ORACLE9I\ORADATA\ORA09\SYSTEM01.DBF
  block no: 83636
  slot no : 4

row no    : 4
  file    : D:\ORACLE9I\ORADATA\ORA09\SYSTEM01.DBF
  block no: 83638
  slot no : 0

row no    : 5
  file    : D:\ORACLE9I\ORADATA\ORA09\SYSTEM01.DBF
  block no: 83640
  slot no : 1

Bigfile rowids

A bigfile tablespace can only have on datafile associated with it, therefor, the three bytes that identified the datafile can now additionally be used to address db blocks.

'Changing' rowids

Although a rowid uniquely identifies a row in a table, it might change its value if the underlying table is an index organized table or a partitioned table.
Also, rowids change if a table is exported and imported using EXP/IMP.

This implies that rowids should not be stored away for later re-use as the corresponding row then might either not exist or contain completely different data.
Misc

Getting the block number (within a segment from a rowid:

select dbms_rowid.rowid_block_number(rowid) from t where ....

from :
阅读(1949) | 评论(0) | 转发(0) |
0

上一篇:linux信号学习

下一篇:Oracle ROWID格式

给主人留下些什么吧!~~