ORA-06502:PL / SQL:数值或值错误

时间:2015-09-15 17:47:30

标签: stored-procedures types plsql oracle11g cursor

我真的很抱歉。我是新的oracle,我创建了以下块,结果是输出,然后是错误。 第一个光标生成输出然后生成错误,因此第二个光标不生成输出。

请提供无错输出帮助。

感谢和问候

错误:

 END;
Error report:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 36
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    
*Action:

块:

  DECLARE 
      c_dbuser SYS_REFCURSOR;
      c_dbuser1 SYS_REFCURSOR;
      temp_dbuser FIT_SCHEMA.fxf_inspt_insp_main%ROWTYPE;

      year_date varchar2(20):='2014';
      typeOfGraph varchar2(50):='InspectionByInspection';
      division varchar2(20):='Division';
      subDiv varchar2(20):='ALL';
      emp varchar2(20):='';


      TYPE t_name IS RECORD(            --Error is at this line :( 
       inspectiondate varchar2(20),
        totalcount number(38),
       inspectionDesc varchar2(20)

      );
      r_name   t_name; -- name record

     TYPE t_monthwise is record (
        month_number varchar2(20),
         inspcount number(38),
      inspectionDesc varchar2(20)


     );

     t_month t_monthwise;
    BEGIN

     fit_schema.My_manager(typeOfGraph,year_date,division,subDiv,emp,c_dbuser,c_dbuser1);

      LOOP

        FETCH c_dbuser INTO  r_name ;

         EXIT WHEN c_dbuser%NOTFOUND;
       dbms_output.put_line( r_name.inspectiondate ||' '||r_name.totalcount||' '||r_name.inspectionDesc);

     END LOOP;  
      LOOP
        FETCH c_dbuser1 INTO  t_month ;


           EXIT WHEN c_dbuser1%NOTFOUND;
        dbms_output.put_line( t_month.month_number ||' '||t_month.inspcount||' '||t_month.inspectionDesc);

    END LOOP;  
       CLOSE c_dbuser;
      CLOSE c_dbuser1;


END;

输出:

13-DEC-2014 1 3#CPLD Only
13-DEC-2014 4 0#Class Only
14-DEC-2014 1 0#Class Only
15-DEC-2014 2 0#Class Only
16-DEC-2014 1 0#Class Only
17-DEC-2014 1 7#Negative Class
17-DEC-2014 9 0#Class Only
19-DEC-2014 15 0#Class Only
22-DEC-2014 1 11#65% Rule
23-DEC-2014 1 8#XLGH & Class
30-DEC-2014 1 0#Class Only
31-DEC-2014 1 10#Mixed Articles
31-DEC-2014 3 0#Class Only
02-JAN-2015 2 0#Class Only
05-JAN-2015 2 0#Class Only
07-JAN-2015 2 9#XLGH Only
07-JAN-2015 3 1#Class & Reweigh
07-JAN-2015 1 10#Mixed Articles
07-JAN-2015 4 0#Class Only
07-JAN-2015 2 11#65% Rule
08-JAN-2015 5 0#Class Only
08-JAN-2015 1 9#XLGH Only
09-JAN-2015 1 3#CPLD Only
09-JAN-2015 1 11#65% Rule
09-JAN-2015 4 0#Class Only
09-JAN-2015 1 1#Class & Reweigh
12-JAN-2015 1 5#CCD Only
12-JAN-2015 1 3#CPLD Only
19-JAN-2015 1 11#65% Rule
20-JAN-2015 1 0#Class Only
21-JAN-2015 4 0#Class Only
23-JAN-2015 1 10#Mixed Articles
26-JAN-2015 1 7#Negative Class
26-JAN-2015 2 0#Class Only
27-JAN-2015 1 3#CPLD Only
27-JAN-2015 3 0#Class Only
27-JAN-2015 1 6#CCD & Class
28-JAN-2015 6 0#Class Only
29-JAN-2015 3 0#Class Only
29-JAN-2015 1 5#CCD Only
30-JAN-2015 1 3#CPLD Only
30-JAN-2015 1 1#Class & Reweigh
01-FEB-2015 3 0#Class Only
02-FEB-2015 1 4#CPLD & Class
02-FEB-2015 1 8#XLGH & Class
04-FEB-2015 1 0#Class Only

来自程序的查询: -

SELECT TO_CHAR(MAINTABLE.INSP_CREATED_TMSTP,'dd-MON-yyyy') inspectiondate,  --varchar2
    COUNT(MAINTABLE.insp_id) AS totalinspection, --count is number
    MAINTABLE.insp_type_id ||'#'||ISNPTYPETABLE.INSP_TYPE_DESC AS INSPECTIONDESCRIPTION-- varchar2
  FROM FIT_SCHEMA.fxf_inspt_insp_main MAINTABLE
  JOIN FIT_SCHEMA.fxf_inspt_emp_detail EMPTABLE
  ON(MAINTABLE.inspector_emp_nbr=EMPTABLE.inspector_emp_nbr)
  JOIN FIT_SCHEMA.fxf_inspt_drop_down DROPDOWNTABLE
  ON (emptable.division_id = DROPDOWNTABLE.drop_down_id)
  JOIN FIT_SCHEMA.fxf_inspt_insp_type ISNPTYPETABLE
  ON(MAINTABLE.insp_type_id                =isnptypetable.insp_type_id)
  WHERE dropdowntable.is_active_flg          = 1
  AND MAINTABLE.STATUS_ID                  = 8
  AND MAINTABLE.insp_type_id              IN (0,1,3,4,5,6,7,8,9,10,11,12) 
  AND TRUNC(MAINTABLE.insp_created_tmstp) between TRUNC(EMPTABLE.EFFECTIVE_FROM_TMSTP)
  And Nvl(Trunc(Emptable.Effective_To_Tmstp),Sysdate)  AND UPPER(dropdowntable.drop_down_grp) =UPPER('division') AND  TRUNC(MAINTABLE.insp_created_tmstp) between '01-JUN-14' AND '31-MAY-15' GROUP BY TO_CHAR(MAINTABLE.INSP_CREATED_TMSTP,'dd-MON-yyyy')
       , TRUNC(MAINTABLE.INSP_CREATED_TMSTP), MAINTABLE.insp_type_id  ||'#'|| ISNPTYPETABLE.INSP_TYPE_DESC ORDER BY TRUNC(MAINTABLE.INSP_CREATED_TMSTP) 


SELECT TO_CHAR(MAINTABLE.insp_created_tmstp,'MM') AS MONTHNUMBER,
    COUNT(MAINTABLE.INSP_ID)                         AS INSPCOUNT ,
    MAINTABLE.insp_type_id ||'#'
    ||ISNPTYPETABLE.INSP_TYPE_DESC AS INSPECTIONDESCRIPTION
    FROM FIT_SCHEMA.fxf_inspt_insp_main MAINTABLE
  JOIN FIT_SCHEMA.fxf_inspt_emp_detail EMPTABLE
  ON(MAINTABLE.inspector_emp_nbr=EMPTABLE.inspector_emp_nbr)
  JOIN FIT_SCHEMA.fxf_inspt_drop_down DROPDOWNTABLE
  ON (emptable.division_id = DROPDOWNTABLE.drop_down_id)
  JOIN FIT_SCHEMA.fxf_inspt_insp_type ISNPTYPETABLE
  ON(MAINTABLE.insp_type_id                       =isnptypetable.insp_type_id)
  WHERE dropdowntable.is_active_flg          = 1
  AND MAINTABLE.insp_type_id     IN (0,1,3,4,5,6,7,8,9,10,11,12) 
  AND dropdowntable.is_active_flg = 1
  AND MAINTABLE.STATUS_ID         = 8
  AND TRUNC(MAINTABLE.insp_created_tmstp)    between TRUNC(EMPTABLE.EFFECTIVE_FROM_TMSTP)
  And Nvl(Trunc(Emptable.Effective_To_Tmstp),Sysdate) AND UPPER(dropdowntable.drop_down_grp) =UPPER('division')
  AND  TRUNC(MAINTABLE.insp_created_tmstp) between '01-JUN-14' 
  AND '31-MAY-15' GROUP BY TO_CHAR(MAINTABLE.insp_created_tmstp,'MM'), MAINTABLE.insp_type_id ||'#'||ISNPTYPETABLE.INSP_TYPE_DESC ORDER BY TO_CHAR(MAINTABLE.insp_created_tmstp,'MM')

1 个答案:

答案 0 :(得分:1)

第36行是:

FETCH c_dbuser INTO  r_name ;

因此,c_dbuser引用游标中返回的值之一太大了。您的日期格式掩码只会生成长度为11个字符的字符串,因此inspectiondate足够(超过),且计数似乎不会超过number(38),因此totalcount似乎也很好。这表明inspectionDesc对于数据中的某些值来说太小了。

您从以下位置生成:

MAINTABLE.insp_type_id ||'#'||ISNPTYPETABLE.INSP_TYPE_DESC

如果该连接字符串的长度超过20个字符,那么您在获取时会收到错误。

如果将INSP_TYPE_DESC定义为varchar2(20),则您不允许任何余地;你需要一个额外的字符用于固定的#,至少两个用于insp_type_id - 如果最高的ID可以是三位数或更多,则需要更多。如果它没有受到限制,那么您需要决定您期望看到的最高数字并允许它。因此,如果您希望ID最多包含三位数字,请将inspectionDesc定义为varchar2(24)等。