在同步两个数据库中的两张表时,使用了merge进行操作。
但是写好的SQL,运行时报ORA-00904:invalid identifier
检查SQL中没有错误的字段名写入。
后发现,在SQLON Clause中出现的连接字段,在UPDATE Clause中也出现了!
如下:
MERGE INTO /*+ parallel(GROUP_PROFILE 4)*/
GROUP_PROFILE Tab1
USING (SELECT *
FROM GROUP_PROFILE_INCREMENT A
WHERE EXISTS
(SELECT 1 FROM VALID_TERMINAL B WHERE A.MOBILEID = B.TERMINALID)) T2
ON (Tab1.Row_Id = T2.ROW_ID)
WHEN MATCHED THEN
UPDATE
SET
Tab1.Row_Id = T2.ROW_ID,
Tab1.GROUPID = T2.GROUPID,
Tab1.GROUPNAME = T2.GROUPNAME,
Tab1.DESTIMID = T2.DESTIMID,
...
WHEN NOT MATCHED THEN
...
去掉红底部分,SQL正常运行。
-----
Restrictions on the merge_update_clause This clause is subject to the following restrictions:
You cannot update a column that is referenced in the ON condition clause.
You cannot specify DEFAULT when updating a view.
Restriction on Merging into a View You cannot specify DEFAULT when updating a view.
另外还需要注意的是,merge会触发目标表上update和insert类型的triger。
9i和10g的说明是基本相同的,之所以说基本,就是9i的说明在merge_update_clause部分的两句和10g顺序正好相反 。
手册,还是手册!
但是写好的SQL,运行时报ORA-00904:invalid identifier
检查SQL中没有错误的字段名写入。
后发现,在SQLON Clause中出现的连接字段,在UPDATE Clause中也出现了!
如下:
MERGE INTO /*+ parallel(GROUP_PROFILE 4)*/
GROUP_PROFILE Tab1
USING (SELECT *
FROM GROUP_PROFILE_INCREMENT A
WHERE EXISTS
(SELECT 1 FROM VALID_TERMINAL B WHERE A.MOBILEID = B.TERMINALID)) T2
ON (Tab1.Row_Id = T2.ROW_ID)
WHEN MATCHED THEN
UPDATE
SET
Tab1.Row_Id = T2.ROW_ID,
Tab1.GROUPID = T2.GROUPID,
Tab1.GROUPNAME = T2.GROUPNAME,
Tab1.DESTIMID = T2.DESTIMID,
...
WHEN NOT MATCHED THEN
...
去掉红底部分,SQL正常运行。
-----
Restrictions on the merge_update_clause This clause is subject to the following restrictions:
You cannot update a column that is referenced in the ON condition clause.
You cannot specify DEFAULT when updating a view.
Restriction on Merging into a View You cannot specify DEFAULT when updating a view.
另外还需要注意的是,merge会触发目标表上update和insert类型的triger。
9i和10g的说明是基本相同的,之所以说基本,就是9i的说明在merge_update_clause部分的两句和10g顺序正好相反 。
手册,还是手册!