从另一个TABLE更新TABLE中的多个列(Oracle)

时间:2009-06-16 14:11:17

标签: sql oracle

我想根据另一个表中的值更新一个表中的多个列。

认为我知道如何在T-SQL中编写一个更新语句来执行我想要的(未经过下面的测试)。问题是我正在尝试将其转换为Oracle数据库。有谁知道如何在Oracle中执行以下操作:

UPDATE oldauth SET
  AUTHUNIQUENAME=newauth.AUTHUNIQUENAME
  DESCRIPTION=newauth.DESCRIPTION
  MAPPINGAUTHNAME=newauth.MAPPINGAUTHNAME
FROM
 (SELECT * FROM USERS1 WHERE AUTHSOURCEID=100) oldauth
LEFT JOIN
 (SELECT * FROM USERS2 WHERE AUTHSOURCEID=200) newauth
ON 
oldauth.AUTHUSERNAME=newauth.AUTHUSERNAME;

1 个答案:

答案 0 :(得分:2)

MERGE
INTO   (
       SELECT  *
       FROM    users1
       WHERE   AUTHSOURCEID=100
       ) oldauth
USING  (
       SELECT  *
       FROM    users2
       WHERE   AUTHSOURCEID=200
       ) newauth
ON     oldauth.AUTHUSERNAME=newauth.AUTHUSERNAME
WHEN MATCHED THEN
UPDATE
SET    AUTHUNIQUENAME=newauth.AUTHUNIQUENAME,
       DESCRIPTION=newauth.DESCRIPTION,
       MAPPINGAUTHNAME=newauth.MAPPINGAUTHNAME