你能给我一个update table语句作为我在oracle数据库上的merge语句吗

xtfmy6hx  于 2021-07-26  发布在  Java
关注(0)|答案(2)|浏览(310)
merge into TableA a
USING TableB  b  
ON (b.name_ID = a.name_id and b.place = a.place
 and b.city=a.city)  
when matched then update set a.status = b.status ,
a.updatedatetime = timestamp 
where address is  null;

你能给上面的合并语句一个更新语句吗

vuktfyat

vuktfyat1#

可能是这样的:

update tablea a set
  (a.status, a.updatedatetime) = 
  (Select b.status, timestamp
   from tableb b
   where b.name_id = a.name_id
     and b.place = a.place
     and b.city = a.city
  )
where a.address is null;

此外,您可能需要添加另一个条件( exists )为了不更新行,您不想:

...
where a.address is null
  --
  and exists (select null
              from tableb c
              where c.name_id = a.name_id
                and c.place = a.place
                and c.city = a.city
             );
bwntbbo3

bwntbbo32#

你可以试试下面-

UPDATE TableA a
   SET (a.status, a.updatedatetime) = (SELECT b.status, timestamp
                                         FROM TableB b
                                        WHERE b.name_ID = a.name_id
                                          AND b.place = a.place
                                          AND b.city=a.city)
 WHERE EXISTS (SELECT 1
                 FROM TableB b
                WHERE b.name_ID = a.name_id
                  AND b.place = a.place
                  AND b.city=a.city) 
   AND address IS NULL;

相关问题