merge在oracle用以從另一張表中取數據插入到一張表中
首先建兩張測試表
Sql代碼
create table mergetest(id number primary key
create table newmergetest(id number primary key
往兩張表中插入數據
Sql代碼
insert into newmergetest values(
insert into newmergetest values(
insert into mergetest values(
insert into mergetest values(
insert into mergetest values(
運行更新sql語句
Sql代碼
MERGE INTO newmergetest m
using (select * from mergetest) t
ON (m
WHEN NOT MATCHED THEN
INSERT VALUES (t
WHEN MATCHED THEN
UPDATE SET m
執行完後
From:http://tw.wingwit.com/Article/program/Oracle/201311/18926.html