问题描述
我想知道,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发生更改.可以通过一个小例子轻松地证明这一点:
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是如何在内部生成的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!