merge into t_pub_test_demo t using (select '52D7183313443210E0540018FE2DA480' as test1 from dual) d on (t.test1 = d.test1) when matched then update set test2 = 2 when not matched then insert (test1, test2, test3, CREATED_BY, DATE_CREATED, UPDATED_BY, DATE_UPDATED) values ('52D7183313443210E0540018FE2DA480', 2, 'test1t', 'system', sysdate, 'system', sysdate);
使用中總結:sql
merge into 表名 別名api
using (查詢語句) 別名spa
on (表達式條件).net
when matched then --當匹配到後面跟的語句,update語句code
注意這裏的update語句不用再寫表名,再也不須要寫where 條件了。blog
正常狀況下應該是:class
update t_pub_test_demo t set test2 = 2 where test1='52D7183313443210E0540018FE2DA480';test
when not matched thendate
看api好像說的是執行一條sql,可是我們這裏就是要實現有就是更新,沒有就新增的功能,因此下面寫insert語句select
細心的確定發現了,這裏的insert也有區別
insert into t_pub_test_demo t (列) values(列)
可是上面沒有。
具體能夠參考如下:
http://blog.csdn.net/suncrafted/article/details/4306677