oracle - ORA 06533下标超出计数

时间:2015-09-15 18:51:28

标签: sql oracle plsql oracle11g

我在执行包时得到ORA-06533。涉及到几件事情,我会尽力做到尽可能详细。

首先我们有这些类型的对象:

CREATE OR REPLACE TYPE TYP_REPORT_IC_OBJ AS OBJECT (
     INTERNAL_DCN  VARCHAR2(30)
    ,IC_ID        VARCHAR2(100)
    ,IC_NUM       NUMBER(38)
    ,IC_CODE      VARCHAR2(15)
    ,CM_CODE      VARCHAR2(7)
    ,IC_VERSION   VARCHAR2(2)
);

CREATE OR REPLACE TYPE TYP_REPORT_IC_TAB IS TABLE TYP_REPORT_IC_OBJ;

在包规范中,我定义了类型(仅显示相关):

TYPE TYP_REPORT_REC IS RECORD (report_ic_tab TYP_REPORT_IC_TAB);
TYPE TYP_REPORT_TAB IS TABLE OF TYP_REPORT_REC INDEX BY PLS_INTEGER;

在正文中,我有一个正在构建动态查询的函数(再次只显示相关代码):

FUNCTION open_report_cur_f 
RETURN SYS_REFCURSOR
IS
v_select_common   VARCHAR2 (20000) :=
               CHR (10)
            || ',CAST(MULTISET(SELECT'                                
            || CHR (10)
            || '                 c.INTERNAL_DCN'
            || CHR (10)
            || '                ,c.IC_ID'
            || CHR (10)
            || '                ,c.IC_NUM'
            || CHR (10)
            || '                ,c.IC_CODE'
            || CHR (10)
            || '                ,c.CM_CODE'
            || CHR (10)
            || '                ,DECODE(c.IC_VERSION,''10'',''0'',NVL(c.IC_VERSION,''9'')) IC_VERSION'
            || CHR (10)
            || '               FROM REPORT_IC c'
            || CHR (10)
            || '               WHERE c.internal_dcn = cr.internal_dcn'
            || CHR (10)
            || '               AND   rownum <= '
            || G_IC_LIMIT
            || ') AS TYP_REPORT_IC_TAB) AS REPORT_IC_TAB';

使用该功能的程序(仅显示相关代码)和TYP_REPORT_TAB。错误发生在注释行下方:

PROCEDURE Put_Records_p
IS
  TYPE REPORT_TABLE_TYPE IS REF CURSOR
     RETURN TYP_REPORT_REC;
   cur_claim_report          REPORT_TABLE_TYPE;
   v_t_report                TYP_REPORT_TAB;
   v_text_line_temp          VARCHAR2 (32767);

          BEGIN
             SELECT TO_DATE (variable_value, 'mm/dd/yyyy')
               INTO g_effective_date
               FROM SYSTEM_CONFIG
              WHERE VARIABLE_NAME = 'EFFECTIVE_DATE';
          EXCEPTION
             WHEN NO_DATA_FOUND
             THEN
                g_effective_date := TO_DATE ('04/01/2015', 'MM/DD/YYYY');
          END;

     cur_cl_report := open_report_cur_f;

     LOOP
        FETCH cur_cl_report
        BULK COLLECT INTO v_t_report
        LIMIT G_BULK_LIMIT;

        IF (v_t_report.COUNT = 0)
        THEN
           EXIT;
        END IF;

        FOR i IN v_t_report.FIRST .. v_t_report.LAST
        LOOP
          IF v_t_report (i).CM_DOI < g_effective_date
          THEN
             v_text_line_temp := v_text_line_temp || RPAD (' ', 1);
          ELSIF v_t_report (i).CM_DOI >= g_effective_date
          THEN
--Line number pointed to below portion. I'm not sure what needs to be added or modified to avoid having the error.
             v_text_line_temp :=
                   v_text_line_temp
                || RPAD(NVL(v_t_report (i).report_ic_tab (1).IC_VERSION, 
                            '0'),
                        1,
                        '0');
          END IF;
        END LOOP;
     END LOOP;
END;

在使用v_text_line_temp构建字符串ORA-06533 Subscript beyond count时似乎抱怨。

更新:在Justin的评论之后,我尝试添加IF条件,只有在NOT NULL处理错误才会处理:

          IF v_t_report (i).report_ic_tab IS NOT NULL
          THEN
             v_text_line_temp :=
                   v_text_line_temp
                || RPAD(NVL(v_t_report (i).report_ic_tab (1).IC_VERSION,
                            '0'),
                        1,
                        '0');
          END IF;

但仍然会出现错误。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

更改您在集合中的迭代方式......

而不是使用

    FOR i IN v_t_report.FIRST .. v_t_report.LAST

    FOR i IN 1.. v_t_report.COUNT

示例:

    PROCEDURE Put_Records_p
    IS
      TYPE REPORT_TABLE_TYPE IS REF CURSOR
         RETURN TYP_REPORT_REC;
       cur_claim_report          REPORT_TABLE_TYPE;
       v_t_report                TYP_REPORT_TAB;
       v_text_line_temp          VARCHAR2 (32767);

              BEGIN
                 SELECT TO_DATE (variable_value, 'mm/dd/yyyy')
                   INTO g_effective_date
                   FROM SYSTEM_CONFIG
                  WHERE VARIABLE_NAME = 'EFFECTIVE_DATE';
              EXCEPTION
                 WHEN NO_DATA_FOUND
                 THEN
                    g_effective_date := TO_DATE ('04/01/2015', 'MM/DD/YYYY');
              END;

         cur_claim_report := open_report_cur_f;

         LOOP
            FETCH cur_claim_report
            BULK COLLECT INTO v_t_report
            LIMIT G_BULK_LIMIT;

            FOR i IN 1..v_t_report.COUNT
            LOOP
              IF v_t_report (i).CM_DOI < g_effective_date
              THEN
                 v_text_line_temp := v_text_line_temp || RPAD (' ', 1);
              ELSIF v_t_report (i).CM_DOI >= g_effective_date
              THEN
    --Line number pointed to below portion. I'm not sure what needs to be added or modified to avoid having the error.
                 v_text_line_temp :=
                       v_text_line_temp
                    || RPAD(NVL(v_t_report (i).report_ic_tab (1).IC_VERSION, 
                                '0'),
                            1,
                            '0');
              END IF;
            END LOOP;

            EXIT WHEN cur_cl_report%NOTFOUND;
         END LOOP;
    END;