MERGE INTO USING用法


MERGE INTO [your table-name] [rename your table here]     
USING ( [write your query here] )[rename your query-sql and using just like a table] ON ([conditional expression here] AND [...]...)     
WHEN MATHED THEN [here you can execute some update sql or something else ]
WHEN NOT MATHED THEN [execute something else here ! ] 

例如:

MERGE INTO table1 a USING ( select id,name from table2) b ON (a.id=b.id)     
WHEN MATHED THEN update set a.name=b.name
WHEN NOT MATHED THEN insert (id,name) values('id','name');

解析:

匹配table1 a,用b這個查詢結果,用on建立聯系,當匹配上用update,匹配不上用insert。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM