合并语句错误想要更新几个表

时间:2015-07-20 10:51:48

标签: sql oracle merge rowid

合并声明显示错误:

MERGE INTO costing.table1 USING
(SELECT table1.ROWID row_id,
        M.STRPS_MATERIAL AS STRPS_MATERIAL
   FROM costing.table2 p
   JOIN costing.table1 M
     ON p.MATNR = M.MATNR
    AND p.WERKS = M.WERKS
    AND p.BESKZ = M.BESKZ
    AND p.SOBSL = M.SOBSL
  WHERE M.SOBSL = '30') src ON (table1.ROWID = src.row_id )
 WHEN MATCHED THEN
   UPDATE SET M.STRPS_MATERIAL = src.STRPS_MATERIAL;


SQL Error: ORA-00904: "table1"."ROWID": invalid identifier
00904. 00000 -  "%s: invalid identifier"

帮助我更正查询,因为rowid不是table1中的列。

1 个答案:

答案 0 :(得分:0)

您可以尝试以下操作。

MERGE INTO costing.table1 USING
  (SELECT M.ROWID row_id,
  M.STRPS_MATERIAL AS STRPS_MATERIAL
  FROM costing.table2 p
 JOIN costing.table1 M
 ON p.MATNR                                           = M.MATNR
 AND p.WERKS                                          = M.WERKS
 AND p.BESKZ                                          = M.BESKZ
 AND p.SOBSL                                          = M.SOBSL
 WHERE M.SOBSL                                        = '30'
 ) src ON (costing.table1.ROWID = src.row_id )
 WHEN MATCHED THEN
 UPDATE SET M.STRPS_MATERIAL = src.STRPS_MATERIAL;