/*Merge into 詳細介紹
MERGE語句是Oracle
通過MERGE語句
連接條件匹配上的進行UPDATE
這個語法僅需要一次全表掃描就完成了全部工作
*/
/*語法
MERGE [INTO [schema
USING [schema
ON ( condition )
WHEN MATCHED THEN merge_update_clause
WHEN NOT MATCHED THEN merge_insert_clause;
*/
語法
MERGE INTO [your table
USING ( [write your query here] )[rename your query
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 ! ]
/*
我們還是以《sql中的case應用》中的表為例
*/
create table fzq
create table fzq
/*涉及到兩個表關聯的例子*/
merge into fzq
using fzq bb
on (aa
when matched then
update set
aa
aa
when not matched then
insert values( bb
/*涉及到多個表關聯的例子
merge into fzq
using (select fzq
from fzq join fzq
on fzq
on (aa
when matched then
update set
aa
/*不能做的事情*/
merge into fzq
using fzq bb
on (aa
when matched then
update set
aa
/*系統提示
ORA
我們不能更新on (aa
update fzq
set id=(select id+
where id in
(select id from fzq)
From:http://tw.wingwit.com/Article/program/Oracle/201311/17876.html