Oracle 2000 万更新基于加入



我需要执行以下操作

  UPDATE TABLE2 t2
SET t2.product_id = (select t1.product_id from
table1 t1 where t1.matching_id = t2.matching_id)

除了 TABLE2 有 2700 万条记录。product_id是新添加的列,因此会向其填充数据。我可以使用光标,将我在 TABLE2 中的记录集分解为一个相当小的数字,但是有 2700 万条记录,我不确定最好的方法是什么。请建议,即使这意味着将我的数据导出到 excel。

更新 - 匹配的列也会被索引。

我唯一能做的不同的事情就是将更新替换为CREATE TABLE AS

  CREATE TABLE table2_new AS
        SELECT t2.* (less product_id), t1.product_id
        FROM table1 t1
        JOIN table2 t2
          ON t1.matching_id = t2.matching_id

但稍后您将不得不手动添加CONSTRAINTS,删除table2并替换table2_new

update (select t1.product_id as old_product_id, t2.product_id as new_product_id
        from table1 t1
        join table2 t2 on (t1.matching_id = t2.matching_id)) t
set t.new_product_id = t.old_product_id

最新更新