我有表格列: xx_org
Org_name source_id source_owner
和另一张表: master_org
name,source_id,source_owner,class
现在我必须使用xx_org中的source_id来更新master_org中的所有source_id,因为xx_org和master_org中的任何组织名称都是常见的。对于不常见的人,不应该做任何事情。
我用过:
update HR.master_org T1,XX_ORG T2
set T1.SOURCE_ID=T2.SOURCE_ID
WHERE t2.ORG_NAME = t1.name ;
但这是错误的:
Error report:
SQL Error: ORA-00971: missing SET keyword
00971. 00000 - "missing SET keyword"
*Cause:
*Action:
看看其他帖子,我也尝试过:
UPDATE
(select TABLE1.SOURCE_ID as old, TABLE2.SOURCE_ID as new
from XX_ORG TABLE1
INNER JOIN HR.master_org table2
ON table1.ORG_NAME = table2.name
) T
SET t.old = t.new
我得到了:
Error report:
SQL Error: ORA-01779: cannot modify a column which maps to a non key-preserved table
01779. 00000 - "cannot modify a column which maps to a non key-preserved table"
*Cause: An attempt was made to insert or update columns of a join view which
map to a non-key-preserved table.
*Action: Modify the underlying base tables directly.
正如Update statement with inner join on Oracle
中所述我尝试使用合并,因为其他查询没有工作,但即使显示1400行合并后,我也看不到我的行更新。我正在使用:
merge
INTO hr.master_org trg
using (
SELECT t1.rowid AS rid, t2.SOURCE_ID,t2.SOURCE_owner
FROM hr.master_org t1
join XX_ORG T2
on T1.ORGANIZATION_NAME = t2.ORG_NAME
where T1.ORGANIZATION_NAME = T2.ORG_NAME
-- and t1.ORGANIZATION_NAME='TMI Operations, M1'
) src
ON (trg.rowid = src.rid)
when matched then update
set TRG.SOURCE_id = SOURCE_id,
TRG.SOURCE_owner = SOURCE_owner;
sample data :
XX_ORG
source_id source_owner org_name
EB73636 EBS TMI
MASTER_ORG
source_id source_owner org_name
EB7363-30-JAN FUSION TMI
我想以这样的方式更新master_org
source_id source_owner org_name
EB73636 EBS TMI