甲骨文 |与其他表比较值后更新大表

发布于 2025-01-11 02:16:15 字数 789 浏览 4 评论 0原文

我有两张大桌子。我们将它们称为 ITEM 表(1807236 条记录)和 ITEM_PROD_DUMP 表(796369 条记录)。 我需要使用主键 (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);

I have two huge tables. Let's call them as ITEM table (1807236 records) and ITEM_PROD_DUMP table (796369 records).
I need to update two columns (total_volume_amount, total_volume_uom) from ITEM table with the values of second table ITEM_PROD_DUMP where their primary key (SYS_ITEM_ID) matches.

I have written a query to do so, it works but only for handful records. For these huge number of records, it just keeps on running.

Can anyone please help me to write a correct and optimal query.

Query I have written:

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄人书 2025-01-18 02:16:15

使用 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;

Use a MERGE statement. Pure and simple. 1.8 million records is not a "huge" number of records.

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文