oracle中merge into用法(用A|B表去更新A|B表或插入A|B表)
参考:https://www.cnblogs.com/kongxc/p/9237941.html
merge into的sql格式:
MERGE INTO [target-table] A USING [source-table sql] B ON([conditional expression] and [...]...) WHEN MATCHED THEN [UPDATE sql] WHEN NOT MATCHED THEN [INSERT sql]
解析:判断B表和A表是否满足ON中条件,如果满足则用B表去更新表,如果不满足,则将插入表
例子:
MERGE INTO A_MERGE A USING (select B.AID,B.NAME,B.YEAR from B_MERGE B) C ON (A.id=C.AID)
WHEN MATCHED THEN
UPDATE SET A.YEAR=C.YEAR
commit;