现在object里面只有code的值,location和position为空,OBJECT的code与RELATION的code是相同的字段,也就是可以拿来做连接的条件。
现在我想把OBJECT里面的值更新,就是根据code到relation去查。
目前用存储过程先根据code去查出position和location之后再更新。但是做起来很慢,我也建了索引。有没有能够之间连接两张表然后直接一步到位的更新方法。
6 个解决方案
#1
merge into
#2
多谢!
#3
直接更新不行么
update OBJECT a
set (location,position) = (select location,position from RELATION b where a.code= b.code)
#4
MERGE INTO OBJECT A
USING RELATION B
ON A.CODE=B.CODE
WHEN MATCHED THEN
UPDATE SET
A.POSITION=B.POSITION,
A.LOCATION=B.LOCATION
USING RELATION B
ON A.CODE=B.CODE
WHEN MATCHED THEN
UPDATE SET
A.POSITION=B.POSITION,
A.LOCATION=B.LOCATION
#5
#6
可以,我试了,多谢二位!
#1
merge into
#2
多谢!
#3
直接更新不行么
update OBJECT a
set (location,position) = (select location,position from RELATION b where a.code= b.code)
#4
MERGE INTO OBJECT A
USING RELATION B
ON A.CODE=B.CODE
WHEN MATCHED THEN
UPDATE SET
A.POSITION=B.POSITION,
A.LOCATION=B.LOCATION
USING RELATION B
ON A.CODE=B.CODE
WHEN MATCHED THEN
UPDATE SET
A.POSITION=B.POSITION,
A.LOCATION=B.LOCATION
#5
#6
可以,我试了,多谢二位!