存储过程中merge into 一般用于增量插入数据,如果是源表全量数据插入目标表常规认为insert into 比merge into 效率更高,
但是数据源表的数据来源是需要查询大量关联表时然后全量录入目标表时,merge into 后面的匹配条件on(0=1) 可以使插入数据效率更高;
具体的执行效率可以看完成同样事物Oracle执行时间的长短;
Oracle 9i引入的功能),其语法如下:
MERGE INTO a_crt_repay_loan t --增量切片
USING (SELECT p_date, load_num, amt1+amt2+amt3+amt4 amt FROM (
SELECT replace(t.REPAY_DATE,'-','') p_date, t.load_num, SUM(amt1) amt1, SUM(amt2) amt2, SUM(amt3) amt3, SUM(amt4) amt4 FROM LOAN_RECYC_temp t GROUP BY t.REPAY_DATE,t.load_num
)) t1--全量切片
ON (t.repay_loan_num = t1.load_num
AND t.repay_date = t1<