连接 Oracle ROWID 上的表

Join tables on Oracle ROWID

我在 Oracle 11g 中有 2 个 tables A 和 B。 Table B 保存与 Table A 完全相同的数据,但具有额外的 ROWID 列,即 Table A.

的 ROWID

我将更改 Table B 中列 colx 的值。然后通过连接 table A 和 table B 更新 table A 中的 colx使用 ROWID。

现在,ROWID 已编码。我应该将 ROWID 转换为 char 吗?当一个是列而另一个是 Oracle ROWID 伪列时,如何在 table A 和 table B 之间进行连接。

UPDATE tablea ta
   SET (colx) = (SELECT colx FROM tableb tb WHERE ta.rowid = tb.rowid)
 WHERE EXISTS (
    SELECT 1
      FROM tableb tb
     WHERE ta.rowid = tb.rowid )

Now, ROWID is encoded.

你不使用标准的oracle类型ROWID吗?如果 - 是,您不需要转换它。 例如,您的 table B 有列 TAB_A_ROWID,其中包含 table A 中相关记录的 rowid。因此您可以轻松加入它们:

select *
from A join B on B.TAB_A_ROWID = A.rowid

顺便说一句,在你的代码中我看到“ta.rowid = tb.rowid”

UPDATE tablea ta
  SET (colx) = (SELECT colx FROM tableb tb WHERE ta.rowid = tb.rowid)

但是rowid是伪列,不能添加列rowid。所以您指定了它们 - 真正的 rowid,而不是来自自己的列。

ROWID是一个伪列,表示数据在数据块中的物理位置。它不是常量,不应用于任何参照完整性或连接。

if you update the partition key and the update causes the row to move from one partition to another - the rowid will CHANGE.

If you use alter table t shrink space compact, the rowid could change

If you use alter table t move, the rowid could change (even without enable row movement)

If you use flashback table t to ...., the rowid could change.

ROWID 只能与真正的主键结合使用(如果有的话)。它不应该用作主键或代替真正的主键。

https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:53140678334596