上传具有架构
的oracle表1 table1 (col1,col2,col3,Primary key :Col2)
。
和upsert语句
MERGE
INTO table1
USING (
SELECT ? AS Col1
, ? AS Col2
, ? AS Col3
FROM dual
) maybe
ON ( maybe.Col2=table1.Col2 )
WHEN NOT MATCHED THEN
INSERT VALUES (
maybe.Col1
, maybe.Col2
, maybe.Col3
)
WHEN MATCHED THEN
UPDATE SET table1.Col1=maybe.Col1
, SET table1.Col3=maybe.Col3
;
结果 发生了异常 java.sql.BatchUpdateException:ORA-01747:user.table.column,table.column或列规范无效
答案 0 :(得分:1)
SET
部分还有一个UPDATE
:
MERGE INTO table1
USING ( SELECT ? AS Col1 , ? AS Col2 , ? AS Col3 FROM dual ) maybe
ON ( maybe.Col2=table1.Col2 )
WHEN NOT MATCHED THEN INSERT VALUES ( maybe.Col1, maybe.Col2, maybe.Col3 )
WHEN MATCHED THEN UPDATE SET table1.Col1=maybe.Col1, SET table1.Col3=maybe.Col3
^^^
应该是:
WHEN MATCHED THEN UPDATE SET table1.Col1=maybe.Col1, table1.Col3=maybe.Col3
不需要table1
说明符,因为更新仅适用于目标表,但它们并不会受到伤害。