Without modifying the table, its hard to capture what has been done. There are solutions out there that add a PL/SQL layer into the MERGE statement to force the execution of PL/SQL function for each row, but that will hurt performance.
If you really need it, an additional column could be added, eg
SQL> create table t as select empno, ename, sal, ' ' tag from scott.emp where empno != 7934;
Table created.
SQL> create table t1 as select empno, ename, sal*5 sal from scott.emp where job = 'CLERK';
Table created.
SQL>
SQL> select * from t;
EMPNO ENAME SAL T
---------- ---------- ---------- -
7369 SMITH 800
7499 ALLEN 1600
7521 WARD 1250
7566 JONES 2975
7654 MARTIN 1250
7698 BLAKE 2850
7782 CLARK 2450
7788 SCOTT 3000
7839 KING 5000
7844 TURNER 1500
7876 ADAMS 1100
7900 JAMES 950
7902 FORD 3000
13 rows selected.
SQL> select * from t1;
EMPNO ENAME SAL
---------- ---------- ----------
7369 SMITH 4000
7876 ADAMS 5500
7900 JAMES 4750
7934 MILLER 6500
SQL>
SQL> merge into t
2 using ( select * from t1) t1
3 on ( t.empno = t1.empno )
4 when matched then
5 update
6 set t.sal = t1.sal, t.tag = 'U'
7 when not matched then
8 insert (t.empno,t.ename,t.sal,t.tag)
9 values (t1.empno,t1.ename,t1.sal,'I');
4 rows merged.
SQL>
SQL> select * from t;
EMPNO ENAME SAL T
---------- ---------- ---------- -
7369 SMITH 4000 U
7499 ALLEN 1600
7521 WARD 1250
7566 JONES 2975
7654 MARTIN 1250
7698 BLAKE 2850
7782 CLARK 2450
7788 SCOTT 3000
7839 KING 5000
7844 TURNER 1500
7876 ADAMS 5500 U
7900 JAMES 4750 U
7902 FORD 3000
7934 MILLER 6500 I
14 rows selected.
I've just used U/I but this column could be (say) a numeric field or similar to handle multiple MERGE's over time.
But most people heading down this route, typically end up using separate INSERT and UPDATE blocks
MERGEworks on multiple records so for a few of them it has anUPDATEaction and for a few of them, it isINSERT. What you are expecting then? It is better to find it using altogether different queries. - PopeyeMERGEthe correct choice if you need to take different actions depending on INSERT or UPDATE ? Why not split your code up in a block forINSERTand a block forUPDATE- Koen Lostrie