oracle rowid是如何在内部生成的? [英] How oracle rowid is generated internally?

查看:600
本文介绍了oracle rowid是如何在内部生成的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,oracle中的ROWID是否递增生成? 如果我在下面的查询中尝试

I want to know, does the ROWID in oracle get generated incrementally? If I try below query

select min(ROWID) from table

我将始终获得表中第一个插入行的ROWID还是最终也可能得到任何随机行的ROWID? 如果有人可以对此有所帮助,将非常有帮助

will I always get the ROWID of first inserted row in the table or I may end up getting a ROWID OF any random row also? It would be very helpful if someone could please throw light in this

推荐答案

最小"行ID将可能不会始终提供表中的第一行.引用文档:

The "minimum" rowid will probably not always provide the first inserted row from the table. To quote from the documentation:

将rowid分配给某一行后,在特殊情况下该rowid可能会更改.例如,如果启用了行移动,则行ID可能会由于分区键更新,闪回表操作,收缩表操作等而发生更改.如果禁用了行移动,则如果使用Oracle数据库实用程序导出和导入行,则rowid可以更改.

After a rowid is assigned to a row piece, the rowid can change in special circumstances. For example, if row movement is enabled, then the rowid can change because of partition key updates, Flashback Table operations, shrink table operations, and so on. If row movement is disabled, then a rowid can change if the row is exported and imported using Oracle Database utilities.

等等" 表示有很多原因会导致rowid发生更改.可以通过一个小例子轻松地证明这一点:

The "and so on" indicates that there are many reasons which would cause a rowid to change. This can easily be demonstrated with a small example:

create table tmp_test ( a number );
insert into tmp_test values (1);
select rowid, a from tmp_test;

ROWID                       A
------------------ ----------
AABo3AAFvAAAda6AAA          1
alter table tmp_test move;
select rowid, a from tmp_test;

ROWID                       A
------------------ ----------
AABo3BAFvAAAdbjAAA          1

您会注意到,在alter table操作之后,唯一的rowid已更改.

You'll notice that after an alter table operation the sole rowid has changed.

如果rowid可以更改,并且由于Oracle没有明确保证最低" rowid始终是插入的第一行,则您可以根据需要采用另一种方式来跟踪它.时间戳或递​​增序列是正常的.

If the rowid can change and as Oracle does not explicitly guarantee that the "lowest" rowid will always be the first inserted row you should have another way of tracking this, if required. A timestamp or an incrementing sequence would be normal.

在不引用任何数据的情况下找到第一个插入的行必须是非常不寻常的要求.如果这是您正在考虑使用的东西,我会再看一下为什么为什么.

It must be a pretty unusual requirement to find the first inserted row without reference to any data. If this is something you're considering using I'd take another look at why you need to do this.

这篇关于oracle rowid是如何在内部生成的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆