Oracle中merge into的使用

2021-08-03 05:16:34 字數 1252 閱讀 5455

語法:

merge

into table_name alias1

using (table|view|sub_query) alias2

on (join condition)

when

matched

then

update table_name

set col1 = col_val1,

col2 = col2_val

when

notmatched

then

insert (column_list) values (column_values);

1.根據newproducts表 來更新products表( 使用表newproducts中的product_name 和category欄位來更新表products 中相同product_id的product_name 和category)

merge

into products p --merge

into 跟的是我們要更新的表

using newproducts np --using 後面接的是條件表

on (p.product_id = np.product_id) --on 後面接的是要更新的表和條件表

連線的條件(可以有多個條件,多個條件用and連線)

when

matched

then -- 滿足on 後面的條件 執行後面的語句(這裡的語句是update也可以是insert

into語句)

update

set p.product_name = np.product_name,

p.category = np.category;

2.當條件不滿足的時候把newproducts表中的資料insert 到表products中

merge

into products p

using newproducts np

on (p.product_id = np.product_id)

when

notmatched

then

insert

values (np.product_id, np.product_name,

np.category);

如何將批處理做成類流處理 merge into

例如 隨著人工智慧的不斷發展,機器學習這門技術也越來越重要,很多人都開啟了學習機器學習,本文就介紹了機器學習的基礎內容。需要在前端頁面上設計成實時的資料,但是沒有flink,所以只能把批處理做成類流處理 更新存在的 update employe as em set salary select sal...

oracle中累計求和 oracle累計求和

poj2001 shortest prefixes trie樹應用 沉迷wow又頹了兩天orz,暴雪爸爸要在國服出月卡了.這是要我好好學習嗎?趕緊來刷題了.oj 題目大意是求所有字串裡每乙個字元 硬體相關 jtag介面 jtag joint test action group,聯合測試行動小組 是一...

oracle中累計求和 oracle累計求和

oracle累計求和 將當前行某列的值與前面所有行的此列值相加,即累計求和 方法一 with t as select 1 val from dual union all select 3 from dual union all select 5 from dual union all select ...