gpt4 book ai didi

sql - oracle rowid是如何在内部生成的?

转载 作者:行者123 更新时间:2023-12-01 11:38:49 24 4
gpt4 key购买 nike

我想知道,oracle中的ROWID是增量生成的吗?如果我尝试以下查询

select min(ROWID) from table

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

最佳答案

“最小”rowid 可能不会总是提供表中第一个插入的行。引用自the documentation :

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 发生变化。这可以很容易地用一个小例子来证明:

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 已更改。

如果 rowid 可以更改,并且由于 Oracle 没有明确保证“最低”rowid 将始终是第一个插入的行,如果需要,您应该有另一种方法来跟踪它。时间戳或递​​增序列是正常的。

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

关于sql - oracle rowid是如何在内部生成的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24076911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com