MERGE不需要“多个表”,但确实需要查询作为源。这样的事情应该起作用:
MERGE INTO mytable dUSING (SELECt 1 id, 'x' name from dual) sON (d.id = s.id)WHEN MATCHED THEN UPDATE SET d.name = s.nameWHEN NOT MATCHED THEN INSERT (id, name) VALUES (s.id, s.name);
或者,您可以在PL / SQL中执行此 *** 作:
BEGIN INSERT INTO mytable (id, name) VALUES (1, 'x');EXCEPTION WHEN DUP_VAL_ON_INDEX THEN UPDATE mytable SET name = 'x' WHERe id = 1;END;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)