merge into 語句使用者

2021-09-02 18:10:13 字數 358 閱讀 7135

merge into 語句

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表去更新a表,如果不滿足,則將b表資料插入a表但是有很多可選項,如下:

表a和表b 通過on 條件進行關聯  當表a中存在表b的資料是則進行更新 不存在是則進行插入

SQL語句merge into的用法

在批量更新大量的資料時,使用insert 和update操作會出現效率低下,甚至卡死的情況。改用 merge into 代替執行批量更新,會提公升執行效率。merge into將源資料 於實際的表,檢視,子查詢 更新或插入到指定的表中 必須實際存在 好處是避免了多個insert 和update操作。...

merge into合併資料

語法 其中as可以省略 merge into table name as table alias using table view sub query as alias on join condition when matched then update set col1 col val1,col2...

Merge into 詳細介紹

merge語句是oracle9i新增的語法,用來合併update和insert語句。通過merge語句,根據一張表或子查詢的連線條件對另外一張表進行查詢,連線條件匹配上的進行update,無法匹配的執行insert。這個語法僅需要一次全表掃瞄就完成了全部工作,執行效率要高於insert update...