尽管不应该输入SQL异常块

时间:2018-08-15 19:51:40

标签: sql oracle exception

我在SQL中有一个过程,该过程从输入列表中读取并插入到表中并返回相同类型的列表,该列表包含所有在插入数据时出现某些异常的记录进桌子。 下面是代码:

CREATE OR REPLACE PROCEDURE TEST(i_EXTRACTION_TYPE_LIST IN EXTRACTION_TYPE_LIST, o_EXTRACTION_TYPE_LIST OUT EXTRACTION_TYPE_LIST) AS 

BEGIN

  FOR i in 1..i_EXTRACTION_TYPE_LIST.COUNT
    LOOP
      BEGIN
         For Process_Name In(
      Select P.Extt_Process_sid, P.Execute_For_Sub_Portfolio_Ind From Extt_Process P 
      Where 
      P.Extt_Acc_Region_Cd=i_EXTRACTION_TYPE_LIST(i).Extt_Acc_Region_Cd And 
      P.Extt_Time_Period_View_Cd=i_EXTRACTION_TYPE_LIST(i).Extt_Time_Period_View_Cd
      )
        Loop
        BEGIN
        If (i_EXTRACTION_TYPE_LIST(i).extt_SubPortfolio_Ind = 'Y' And Process_Name.Execute_For_Sub_Portfolio_Ind = 'N') = FALSE Then
          Insert Into Extt_Process_Execution Pe(
            Pe.Extt_Process_Exec_Sid,
            Pe.Extt_Process_sid, 
            Pe.Extt_Process_Exec_Start_Ts,
            Pe.Extt_Portfolio_Id,
            Pe.Extt_Process_Exec_Status_Cd,
            Pe.Report_From_Dt,
            Pe.Report_To_Dt,
            Pe.Created_By_Id,
            Pe.Created_Ts,
            UPDATED_BY_ID,
            UPDATED_TS)
            Values(
            Apex_De_Seq.Nextval,
            Process_name.extt_process_sid,
            i_EXTRACTION_TYPE_LIST(i).Extt_Process_Exec_Start_Ts,
            i_EXTRACTION_TYPE_LIST(i).Extt_Portfolio_Id,
            i_EXTRACTION_TYPE_LIST(i).Extt_Process_Exec_Status_Cd,
            i_EXTRACTION_TYPE_LIST(i).Report_From_Dt,
            i_EXTRACTION_TYPE_LIST(i).Report_To_Dt,
            user,
            Systimestamp,
            user,
            Systimestamp
            );

        END IF;
        EXCEPTION
            WHEN others then

            IF o_EXTRACTION_TYPE_LIST IS NULL THEN
            o_EXTRACTION_TYPE_LIST:=EXTRACTION_TYPE_LIST(i_EXTRACTION_TYPE_LIST(i));

            ELSE

          o_EXTRACTION_TYPE_LIST.extend();

          o_EXTRACTION_TYPE_LIST(o_EXTRACTION_TYPE_LIST.count):=i_EXTRACTION_TYPE_LIST(i);
          END IF;
          DBMS_OUTPUT.PUT_LINE(o_EXTRACTION_TYPE_LIST.count);
        END;
        End Loop;
      END;
      END LOOP;
END TEST;

为此,DBMS输出为1,即使我插入的记录是完美的,也不会引起任何异常。我相信我处理异常或块作用域的方式搞砸了。请帮忙!

1 个答案:

答案 0 :(得分:0)

您说您不应该进入您的异常块,但是您已经进入了,因此必须发生某种异常。将dbms_output.put_line(sqlerrm)添加到您的异常块中以确定正在发生的情况。可以推测出什么地方出了错。