我正在使用下面的BULK COMMIT
proc 将记录从TABLESOURCE
to插入TABLE1
。
COLUMN1
onTABLE1
定义为NOT NULL
。
有时我TABLE_SOURCE
返回零行,在这种情况下,我的 PROC 失败并出现错误:
Ora - 6502 数值或数值错误
我尝试使用NO_DATA_FOUND
in 异常忽略该错误,但它也不起作用。
你能告诉我如何解决这个问题吗?
create or replace PROCEDURE PROC1 AS
v_ErrNum NUMBER (20);
v_ErrMsg VARCHAR2 (270);
v_Last_Record PLS_INTEGER;
CURSOR c_Get_Record
IS
SELECT Column1, Column2, Column3
FROM Table1;
TYPE Target_Rec IS TABLE OF Table1%ROWTYPE
INDEX BY PLS_INTEGER;
a_Target_Rec Target_Rec;
TYPE FetchSet IS TABLE OF c_Get_Record%ROWTYPE;
a_Fetch_Set FetchSet;
TYPE cursor_var_type IS REF CURSOR;
CV cursor_var_type;
BEGIN
OPEN CV FOR
Select Column1, Column2, Column3 from TABLE_SOURCE where Column1 is NOT NULL;
FETCH CV
BULK COLLECT INTO a_Fetch_Set;
CLOSE CV;
v_Last_Record := a_Fetch_Set.LAST;
FOR i IN 1 .. v_Last_Record
LOOP
a_Target_Rec (i).Column1 := a_Fetch_Set (i).Column1;
a_Target_Rec (i).Column2 := a_Fetch_Set (i).Column2;
a_Target_Rec (i).Column3 := a_Fetch_Set (i).Column3;
END LOOP;
v_Last_Record := 0;
v_Last_Record := a_Target_Rec.LAST;
FORALL j IN 1 .. v_Last_Record
INSERT INTO TABLE1
VALUES a_Target_Rec (j);
COMMIT;
-- *** ** Error Handling ** ***
EXCEPTION
WHEN OTHERS THEN
v_ErrNum := SQLCODE ;
v_ErrMsg := SUBSTR( SQLERRM, 0, 250) ;
RAISE_APPLICATION_ERROR( -20067 , 'ERROR WHILE LOADING TABLE1 Error Msg: ' || dbms_utility.format_error_stack|| dbms_utility.format_error_backtrace) ;
ROLLBACK ;
END PROC1;