oracle更新表
我试图更新oracle表的一行,update的值在另一个表中。在第一个表中,我有两行,他们可以在第二个表中确定值 我试着说这两句话:oracle更新表,oracle,sql-update,Oracle,Sql Update,我试图更新oracle表的一行,update的值在另一个表中。在第一个表中,我有两行,他们可以在第二个表中确定值 我试着说这两句话: merge into participacion pn using( select valor_documento,id_tipo_documento,id_participante from participantes ) par on ( pn.valor_documento=par.valor_documento and pn.id_tipo_docum
merge into participacion pn
using(
select valor_documento,id_tipo_documento,id_participante from
participantes
) par
on (
pn.valor_documento=par.valor_documento
and pn.id_tipo_documento=par.id_tipo_documento
)
WHEN MATCHED THEN UPDATE
SET pn.id_participante = par.id_participante
或:
在这两种情况下,更新都花费了大量时间,因为我在一个表中有500000行,在另一个表中有3500000多行
关于如何进行此更新,您还有其他想法吗?您的合并语句可以重写为:
merge into participacion pn
using participantes par
on (pn.valor_documento = par.valor_documento
and pn.id_tipo_documento = par.id_tipo_documento)
when matched then
update set pn.id_participante = par.id_participante;
(也就是说,由于源查询正在从participantes表中选择所有内容,并且您没有进行任何计算,因此不需要使用子查询,您可以直接引用该表)
IMHO说,这两种形式的合并都是最直接、最有效的更新方式。因此,考虑到这一点,您可能需要查看索引—您希望两个表之间的连接产生多少行?也许从participation表中对(valor_documento,id_tipo_documento)建立索引有助于加快速度,这取决于合并会影响多少行。最后,我创建了一个这样的索引 在参与者(valor_documento,id_tipo_documento)上创建索引PK_temporal
然后我更新了表,更新只需2分钟,更新后我就删除了索引。你尝试过批量收集概念吗?我想这篇文章会有帮助:我不知道,直到没有这个概念,谢谢,我会尝试一个表有500000行,另一个表有3500000行。下个星期一我试试,我会给你这个案子最好的选择
merge into participacion pn
using participantes par
on (pn.valor_documento = par.valor_documento
and pn.id_tipo_documento = par.id_tipo_documento)
when matched then
update set pn.id_participante = par.id_participante;