Is it possible to report an error (raise exception or anything) in merge's when-not-matched-then clause? I'm aiming for something like
WHEN NOT MATCHED THEN RAISE NO_DATA_FOUND;
Or anything that will tell the caller that script failed.
oracle
Is it possible to report an error (raise exception or anything) in merge's when-not-matched-then clause? I'm aiming for something like
WHEN NOT MATCHED THEN RAISE NO_DATA_FOUND;
Or anything that will tell the caller that script failed.
Best Answer
You can do this using a trigger.
Note: This is HORRIBLE, but I can't think of another way of achieving this.
Test tables:
Trigger on merge table:
Merge:
Basically, when a row doesn't match, we set some values (that your application will never use, yes I know it is a horrible way of doing it!) in the
INSERT
that the trigger looks for, then fires an error.Test case: