I have the following merge procedure. How can I access values from merge statement in exception handling part…
procedure merge_students
is
begin
merge into
students a
using
studentstmp t
on
(a.code = t.code)
when matched then update set a.name = t.name,
when not matched then insert (code,name)
values (t.code,t.name);
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN
dbms_output.put_line('students code: ' || a.code); //how to access a.code here
dbms_output.put_line('studentsTMP code: ' || t.code); // and t.code here
end;
Depending on the Oracle version, you could use DML error logging. Something along the lines of
Create the Source & Destination Tables with Data
Create the Error Log Table
MERGE with the LOG ERRORS syntax
Note that one row was sucessfully merged while one row generated a unique constraint exception and was written to the error table.