如何对多个 FORALL 语句分别进行异常处理
how to do exception handling separately for more than one FORALL statement
如何处理每个 forall
的异常,因为两个插入的插入数据收集不同。
错误:
Error(37,8): PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: ( begin case declare end exit for goto if loop mod null pragma raise return select update when while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge
Error(113,33): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: end not pragma final instantiable order overriding static member constructor map
create or replace PROCEDURE INSRT_MISSG_DATA_TO_TBL IS
l_errors number;
l_errno number;
l_msg varchar2(4000);
l_idx number;
TYPE t_payment IS TABLE OF PAYMENT%ROWTYPE;
TYPE t_payment_alternate_id IS TABLE OF PAYMENT_ALT_ID%ROWTYPE;
list_payment t_payment := t_payment();
list_payment_alternate_id t_payment_alternate_id := t_payment_alternate_id();
BEGIN
FORALL i IN 1 .. list_payment.COUNT SAVE EXCEPTIONS
INSERT INTO PAYMENT VALUES list_payment(i);
EXCEPTION
WHEN OTHERS THEN
l_errors := SQL%BULK_EXCEPTIONS.COUNT;
FOR i in 1 .. l_errors
LOOP
l_errno := SQL%BULK_EXCEPTIONS(i).ERROR_CODE;
l_msg := SQLERRM(-l_errno);
l_idx := SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
insert into ERROR_LOG
( ora_err_no, ora_err_msg, err_payment_id, err_event_id )
values
( l_errno, l_msg, list_payment(l_idx).payment_id, null );
END LOOP;
FORALL i IN 1 .. list_payment_alternate_id.COUNT SAVE EXCEPTIONS
INSERT INTO PAYMENT_ALT_ID VALUES list_payment_alternate_id(i);
EXCEPTION
WHEN OTHERS THEN
l_errors := SQL%BULK_EXCEPTIONS.COUNT;
FOR i in 1 .. l_errors
LOOP
l_errno := SQL%BULK_EXCEPTIONS(i).ERROR_CODE;
l_msg := SQLERRM(-l_errno);
l_idx := SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
insert into ERROR_LOG
( ora_err_no, ora_err_msg, err_payment_id, err_event_id )
values
( l_errno, l_msg, list_payment(l_idx).payment_id, null );
END LOOP;
END INSRT_MISSG_DATA_TO_PODS_TBL;
这是您的代码的简化版本;我想你会明白的,希望它会好起来的。基本上,您需要将每个 FORALL 包含在它自己的 BEGIN-END 块中。
create or replace procedure ...
begin
begin
forall ...
insert into ...
exception
when others then ...
end;
begin
forall ...
insert into ...
exception
when others then ...
end;
end
如何处理每个 forall
的异常,因为两个插入的插入数据收集不同。
错误:
Error(37,8): PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: ( begin case declare end exit for goto if loop mod null pragma raise return select update when while with << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge
Error(113,33): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: end not pragma final instantiable order overriding static member constructor map
create or replace PROCEDURE INSRT_MISSG_DATA_TO_TBL IS
l_errors number;
l_errno number;
l_msg varchar2(4000);
l_idx number;
TYPE t_payment IS TABLE OF PAYMENT%ROWTYPE;
TYPE t_payment_alternate_id IS TABLE OF PAYMENT_ALT_ID%ROWTYPE;
list_payment t_payment := t_payment();
list_payment_alternate_id t_payment_alternate_id := t_payment_alternate_id();
BEGIN
FORALL i IN 1 .. list_payment.COUNT SAVE EXCEPTIONS
INSERT INTO PAYMENT VALUES list_payment(i);
EXCEPTION
WHEN OTHERS THEN
l_errors := SQL%BULK_EXCEPTIONS.COUNT;
FOR i in 1 .. l_errors
LOOP
l_errno := SQL%BULK_EXCEPTIONS(i).ERROR_CODE;
l_msg := SQLERRM(-l_errno);
l_idx := SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
insert into ERROR_LOG
( ora_err_no, ora_err_msg, err_payment_id, err_event_id )
values
( l_errno, l_msg, list_payment(l_idx).payment_id, null );
END LOOP;
FORALL i IN 1 .. list_payment_alternate_id.COUNT SAVE EXCEPTIONS
INSERT INTO PAYMENT_ALT_ID VALUES list_payment_alternate_id(i);
EXCEPTION
WHEN OTHERS THEN
l_errors := SQL%BULK_EXCEPTIONS.COUNT;
FOR i in 1 .. l_errors
LOOP
l_errno := SQL%BULK_EXCEPTIONS(i).ERROR_CODE;
l_msg := SQLERRM(-l_errno);
l_idx := SQL%BULK_EXCEPTIONS(i).ERROR_INDEX;
insert into ERROR_LOG
( ora_err_no, ora_err_msg, err_payment_id, err_event_id )
values
( l_errno, l_msg, list_payment(l_idx).payment_id, null );
END LOOP;
END INSRT_MISSG_DATA_TO_PODS_TBL;
这是您的代码的简化版本;我想你会明白的,希望它会好起来的。基本上,您需要将每个 FORALL 包含在它自己的 BEGIN-END 块中。
create or replace procedure ...
begin
begin
forall ...
insert into ...
exception
when others then ...
end;
begin
forall ...
insert into ...
exception
when others then ...
end;
end