There are 2 types of bulk exceptions
1) When the exception occurs inside the body of the bulk
2) When the exception occurs inside FORALL statement
For exception 1,
the below statement does not work
print_log(l_module_name||' : number of statements that failed -'||l_err_count);
it works only for exception 2, because whenever there is an exception in the body of the bulk, the it directly goes to WHEN OTHERS.
BEGIN
OPEN cur_get_bulk_transactions ( l_bulk_lot (l).organization_id
, l_bulk_lot (l).inventory_item_id
, l_bulk_lot (l).lot_number
, p_trx_date_from
, p_trx_date_to);
LOOP
FETCH cur_get_bulk_transactions
BULK COLLECT INTO l_bulk_trx;
FOR t IN 1 .. l_bulk_trx.COUNT
LOOP
print_log(l_module_name||' : Inside cur_get_bulk_transactions');
-- generate the record_id
-- if there are any errors, raise exception as record_id is the primary key
BEGIN
SELECT xxgil_lot_status_report_seq.NEXTVAL
INTO l_bulk_trx (t).record_id
FROM dual;
EXCEPTION
WHEN OTHERS THEN
l_err_msg := SQLERRM;
l_err_msg:= substr(l_err_msg||' Unable to set record_id', 1, 32000);
RAISE e_track;
END;
print_log(l_module_name||' : xxgil_lot_status_report_seq.NEXTVAL - '||l_bulk_trx (t).record_id);
print_log(l_module_name||' : l_bulk_lot (l).mfg_date - '||l_bulk_lot (l).mfg_date);
-- assign the mfg and release date derived from the CURSOR cur_get_bulk_lots
l_bulk_trx (t).mfg_date := to_date (l_bulk_lot (l).mfg_date, 'YYYY/MM/ HH24:MI:SS');
l_bulk_trx (t).release_date := l_bulk_lot (l).release_date;
l_bulk_trx (t).status := 'N';
print_log(l_module_name||' : l_bulk_trx (t).mfg_date - '||l_bulk_trx (t).mfg_date);
print_log(l_module_name||' : l_bulk_trx (t).release_date - '||l_bulk_trx (t).release_date);
print_log(l_module_name||' : l_bulk_trx (t).status - '||l_bulk_trx (t).status);
END LOOP;
print_log(l_module_name||' : Outside l_bulk_trx (t) END LOOP - ');
EXIT WHEN l_bulk_trx.COUNT = 0;
FORALL x IN l_bulk_trx.FIRST .. l_bulk_trx.LAST
INSERT INTO xxgil.xxgil_bulk_lot_status VALUES l_bulk_trx (x);
COMMIT;
END LOOP;
print_log(l_module_name||' : BEFORE CLOSE cur_get_bulk_transactions - ');
CLOSE cur_get_bulk_transactions;
print_log(l_module_name||' : AFTER CLOSE cur_get_bulk_transactions - ');
EXCEPTION
WHEN OTHERS THEN
print_log(l_module_name||'INSIDE OTHERS EXCEPTION');
l_err_count := SQL%BULK_EXCEPTIONS.COUNT;
print_log(l_module_name||' : number of statements that failed -'||l_err_count);
FOR i IN 1..l_err_count
LOOP
print_log(l_module_name||' : error #' || i || ' occurred during '||'iteration #' || SQL%bulk_exceptions(i).error_index);
print_log(l_module_name||' : error message is ' ||SQLERRM(SQL%bulk_exceptions(i).error_code));
END LOOP;
-- reset the error counter
l_err_count := 0;
print_log(l_module_name||'ENDING OTHERS EXCEPTION');
END;
1) When the exception occurs inside the body of the bulk
2) When the exception occurs inside FORALL statement
For exception 1,
the below statement does not work
print_log(l_module_name||' : number of statements that failed -'||l_err_count);
it works only for exception 2, because whenever there is an exception in the body of the bulk, the it directly goes to WHEN OTHERS.
BEGIN
OPEN cur_get_bulk_transactions ( l_bulk_lot (l).organization_id
, l_bulk_lot (l).inventory_item_id
, l_bulk_lot (l).lot_number
, p_trx_date_from
, p_trx_date_to);
LOOP
FETCH cur_get_bulk_transactions
BULK COLLECT INTO l_bulk_trx;
FOR t IN 1 .. l_bulk_trx.COUNT
LOOP
print_log(l_module_name||' : Inside cur_get_bulk_transactions');
-- generate the record_id
-- if there are any errors, raise exception as record_id is the primary key
BEGIN
SELECT xxgil_lot_status_report_seq.NEXTVAL
INTO l_bulk_trx (t).record_id
FROM dual;
EXCEPTION
WHEN OTHERS THEN
l_err_msg := SQLERRM;
l_err_msg:= substr(l_err_msg||' Unable to set record_id', 1, 32000);
RAISE e_track;
END;
print_log(l_module_name||' : xxgil_lot_status_report_seq.NEXTVAL - '||l_bulk_trx (t).record_id);
print_log(l_module_name||' : l_bulk_lot (l).mfg_date - '||l_bulk_lot (l).mfg_date);
-- assign the mfg and release date derived from the CURSOR cur_get_bulk_lots
l_bulk_trx (t).mfg_date := to_date (l_bulk_lot (l).mfg_date, 'YYYY/MM/ HH24:MI:SS');
l_bulk_trx (t).release_date := l_bulk_lot (l).release_date;
l_bulk_trx (t).status := 'N';
print_log(l_module_name||' : l_bulk_trx (t).mfg_date - '||l_bulk_trx (t).mfg_date);
print_log(l_module_name||' : l_bulk_trx (t).release_date - '||l_bulk_trx (t).release_date);
print_log(l_module_name||' : l_bulk_trx (t).status - '||l_bulk_trx (t).status);
END LOOP;
print_log(l_module_name||' : Outside l_bulk_trx (t) END LOOP - ');
EXIT WHEN l_bulk_trx.COUNT = 0;
FORALL x IN l_bulk_trx.FIRST .. l_bulk_trx.LAST
INSERT INTO xxgil.xxgil_bulk_lot_status VALUES l_bulk_trx (x);
COMMIT;
END LOOP;
print_log(l_module_name||' : BEFORE CLOSE cur_get_bulk_transactions - ');
CLOSE cur_get_bulk_transactions;
print_log(l_module_name||' : AFTER CLOSE cur_get_bulk_transactions - ');
EXCEPTION
WHEN OTHERS THEN
print_log(l_module_name||'INSIDE OTHERS EXCEPTION');
l_err_count := SQL%BULK_EXCEPTIONS.COUNT;
print_log(l_module_name||' : number of statements that failed -'||l_err_count);
FOR i IN 1..l_err_count
LOOP
print_log(l_module_name||' : error #' || i || ' occurred during '||'iteration #' || SQL%bulk_exceptions(i).error_index);
print_log(l_module_name||' : error message is ' ||SQLERRM(SQL%bulk_exceptions(i).error_code));
END LOOP;
-- reset the error counter
l_err_count := 0;
print_log(l_module_name||'ENDING OTHERS EXCEPTION');
END;