【发布时间】:2018-02-07 21:59:51
【问题描述】:
我有table1 和table2。它们具有相同的列,而 ID 列是我可以用来连接表的列。
我如何运行 foreach 语句,它将用 table2 中的列 Name 的值更新 table1 中的行 Name?
我需要这个,所以我可以修复Table1 中的Name 列,因为它不正确,它的好值在table2 中
我尝试使用单个更新语句,但它需要很长时间才能执行,因为两个表都有超过 600 000 行
update
table1 t1
set
(
t1.name
) = (
select
t2.name
from
table2 t2
where
t2.id = t1.id
and
rownum = 1
)
where exists (
select
null
from
table2 t2
where
t2.id = t1.id
);
【问题讨论】:
-
到目前为止你尝试了什么????
-
我尝试使用一次更新,但这些表的行数超过 600000 行,执行 update table1 t1 set ( t1.name ) = ( select t2.name from table2 t2 where t2.id 需要很长时间= t1.id and rownum = 1 ) where exists (select null from table2 t2 where t2.id = t1.id );
-
不是评论,而是编辑您的问题。
-
我认为你应该谷歌一个教程
-
你试过谷歌吗???这个链接是谷歌出来的第一个结果。 stackoverflow.com/questions/2446764/…
标签: sql oracle join sql-update