使用merge into方式進行資料導入
文法:
merge into 目标表 a
using 源表 b
on(a.條件字段1=b.條件字段1 and a.條件字段2=b.條件字段2 ……)
when matched then update set a.更新字段=b.字段
when not macthed then insert into a(字段1,字段2……)values(值1,值2……)
示例:
ALTER SESSION SET NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss';
select sysdate from dual;
MERGE INTO tab1 a
using (select/*parallel(b,24)*/ * from tab2 where id in (1,2,3)) b
on (b.id=a.id)
WHEN MATCHED THEN
update
set
a.id=b.id,
a.name=b.name
WHEN NOT MATCHED THEN
INSERT VALUES
(b.id,
b.name);
commit;
select sysdate from dual;
根據測試總結:
當表資料量在百萬級别時,該方式可行。但是如若在千萬級别或者億級别,該方案不可行,執行速度較慢,導緻oracle停滞時間較長。