Merge Into 用法

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执行时,会从using 搜出来的结果逐条与 on条件匹配,然后决定是update还是Insert。
所以using后面的sql没有查询到数据这个Merge Into语句是不会执行update和Insert操作的。
因此,单表操作时,只能写成两个sql先能生效

转载于:https://my.oschina.net/u/2552902/blog/543898

猜你喜欢

转载自blog.csdn.net/weixin_33724659/article/details/92326550
今日推荐