在Oracle MERGE中使用该ID加入时更新ID

时间:2013-08-21 18:56:02

标签: sql oracle

表1:PERSON

ID, colx...

10
20
30
40
50
60

Table 2: TBL_MERGE

ID, colx..., Old_ID

 10, ...,    null
 20, ...,    null
300, ...,    30
 40, ...,    null
 50, ...,    null
600, ...,    60

我想根据此标准用表2(TBL_MERGE)更新表1(PERSON)。

伪代码:

if tbl_merge.old_id is not null and tbl_merge.old_id = person.id then
    person.id = tbl_merge.id

由于

1 个答案:

答案 0 :(得分:1)

UPDATE person p set ID = (SELECT t.ID FROM tbl_merge t where t.old_id = p.ID)
WHERE EXISTS (Select 1 FROM tbl_merge t where t.old_id = p.ID)