我有两张大桌子。让我们将它们称为ITEM表(1807236条记录)和ITEM_PROD_DUMP表(796369条记录)。我需要用第二个表(total_volume_amount, total_volume_uom)的值更新ITEM表中的两个列( ITEM_PROD_DUMP ),其中它们的主键(SYS_ITEM_ID)匹配。
为此,我编写了一个查询,它可以工作,但只适用于少数记录。对于这些巨大的记录,它只是继续运行。
谁能帮我写一个正确和最优的查询。
我编写的查询:
update item i set i.total_volume_amount = (select ipd.total_volume_amount
from item_prod_dump ipd
where i.sys_item_id = ipd.sys_item_id),
i.total_volume_uom = (select ipd.total_volume_uom
from item_prod_dump ipd
where i.sys_item_id = ipd.sys_item_id)
where exists (select ipd.total_volume_amount
from item_prod_dump ipd
where i.sys_item_id = ipd.sys_item_id);发布于 2022-03-02 13:06:38
使用MERGE语句。单纯而简单。180万条记录并不是“大量”的记录。
merge into item t
using ( SELECT *
FROM item_prod_dump ipd ) u
on ( t.sys_item_id = u.sys_item_id )
when matched then update set t.total_volume_amount = u.total_volume_amount,
t.total_volume_uom = u.total_volume_uom;https://stackoverflow.com/questions/71323146
复制相似问题