Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2829325
  • 博文数量: 221
  • 博客积分: 10045
  • 博客等级: 上将
  • 技术积分: 2252
  • 用 户 组: 普通用户
  • 注册时间: 2005-01-25 20:28
文章分类

全部博文(221)

文章存档

2012年(1)

2008年(4)

2007年(11)

2006年(26)

2005年(179)

我的朋友

分类: Oracle

2005-05-21 15:46:15

select col_1, col_2, rowid from some_table

A rowid identifies a row in a table

A rowid is a (like ), 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

Using dbms_rowid

In order to find the datafile, block number and slot number, can be used:
 on size 1000000 format wrapped

 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_filename .file_name%type;
begin
  for p in (
    select
      rowid 
    from 
      rowid_test
    ) loop

     select
       file_name
     into 
       v_filename
     from 
       
     where
       file_id = (p.rowid);


     .put_line('row no    : ' || i         );
     .put_line('  file    : ' || v_filename);
     .put_line('  block no: ' || );
     .put_line('  slot no : ' || );
     .put_line('');

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

drop table rowid_test;

row no    : 1
  file    : D:ORACLEDATABASESORA10DATA.DBF
  block no: 3890
  slot no : 19

row no    : 2
  file    : D:ORACLEDATABASESORA10DATA.DBF
  block no: 3890
  slot no : 39

  [....]

Bigfile rowids

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

'Changing' rowids

Although a rowid uniquely identifies a row in a table, it might change its value if the underlying table is an or a .
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 from a rowid:
select .rowid_block_number(rowid) from t where ....
阅读(1461) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~