views:

101

answers:

1

Given an Oracle Merge statement with a rejection limit, is there a shorthand way to identify how many rows were rejected, without being forced to query the rejection destination?

The rejection destination has records pre-merge, so would currently have to be counted twice and the difference taken, but it seems like there should be a counter exposed, given that it has to be aware of whether it has exceeded the rejection limit.

+2  A: 

There is no exposed rejection counter.

The main purpose of DML Error Logging is to support ETL processes. It allows us to load huge amounts of data without a couple of errors forcing the entire load to rollback. I guess the underlying rationale is that errors will be resolved manually before we issue more DML against that table: it's not really intended to provide a permanent error log.

However, if you give each DML statement a unique tag you can count the exact number of rejections it has spawned.

declare
    l_tag varchar2(46);
    reject_cnt pls_integer;
begin

    ....

    l_tag := 'merging from source_table::'||to_char(sysdate, 'yyyymmddhh24miss');

    merge into target_table a
        using source_table b
        on (a.id = b.id)
      ....
      log errors into err$_target_table (l_tag) reject limit 10;

    select count(*)
    into reject_cnt
    from   err$_target_table
    where  ora_err_tag$ = l_tag;

    ....
APC
It's not being used as a permanent error log, the imports are automated and relatively frequent, so the previous errors are not guarenteed to of been resolved at the time of the subsequent import. Looks like I am forced to double count the table.
Andrew