我在第109行收到错误," ORA-06533:超出计数的下标"

时间:2015-03-23 17:47:02

标签: sql plsql

我在第109行收到错误,“ORA-06533:超出计数的下标”。仅当特定员工的记录数超过70时才会出现此情况。

错误报告:

ORA-06533: Subscript beyond count
ORA-06512: at line 109
06533. 00000 -  "Subscript beyond count"
*Cause:    An in-limit subscript was greater than the count of a varray
           or too large for a nested table.


  declare

      type v_dt is varray(30000) of date;
          v_visit v_dt := v_dt();

      i number :=0;
      j number :=0;
      v_max_prod number :=0;
      v_max_visit number :=0;
      v_create_sql varchar2(4000 char) :='';
      v_insert_sql varchar2(4000 char) :='';
      v_insert_sql_val varchar2(4000 char) :='';
      v_create_col_head varchar2(4000 char) :='';
      v_insert_col_head varchar2(4000 char) :='';
      v_tbl_ext  number;
      cursor al is select distinct team_name,employee_name from TMP_BMS_RPT_3 where  employee_name in ('JAY DESAI')  order by employee_name;
--(Here i am taking an example of employee whose having more then 200 records in TMP_BMS_RPT_3 table and i am getting this error. )    

    begin

      select max(total_call) into v_max_visit from TMP_BMS_RPT_3 ;
      select count(1) into v_tbl_ext from tab where lower(tname) like 'tmp_bms_monthly_report';



      if v_tbl_ext >= 1 then
        execute immediate 'drop table tmp_BMS_monthly_report';
        execute immediate 'drop table tmp_BMS_monthly_rpt_heading';
      end if;
      v_create_sql := 'create table tmp_BMS_monthly_report (
                           team_name varchar2(100),
                             CCA_USER_ID varchar2(100),
                           EMPLOYEE_NAME  varchar2(100),
                           FLM  varchar2(100),
                           ad_Sales varchar2(100),
                           Client_Customer_id varchar2(100),
                           customer_name varchar2(100),
                           specialty varchar2(100),
                           brand varchar2(100),
                           class varchar2(100),
                           Planned_calls Number,
                           total_call number,
                           Last_visit DATE';



      v_create_col_head := 'create table tmp_BMS_monthly_rpt_heading (
                           team_name varchar2(100),
                           CCA_USER_ID varchar2(100),
                           EMPLOYEE_NAME  varchar2(100),
                           FLM  varchar2(100),
                           ad_Sales varchar2(100),
                           Client_Customer_id varchar2(100),
                           customer_name varchar2(100),
                           specialty varchar2(100),
                           brand varchar2(100),
                           class varchar2(100),
                           Planned_calls varchar2(100),
                           total_call varchar2(100),
                           Last_visit varchar2(100)';

       for i in 1..v_max_visit loop
          v_create_sql := v_create_sql || ',Visit_' ||i ||'     date';
          v_create_col_head := v_create_col_head || ',Visit_' ||i ||'       varchar2(50)';
      end loop i;
      v_create_sql := v_create_sql ||')';
      v_create_col_head := v_create_col_head ||')';
      execute immediate v_create_sql;
      execute immediate v_create_col_head;

      v_insert_col_head := 'insert into tmp_BMS_monthly_rpt_heading values (''Team_name'',''CCA_USER_ID'',''EMPLOYEE_NAME'',''FLM'',''Ad_Sales'',''Client_Customer_id'',''Customer_name'',''Specialty '',''brand'',''Class'',''Planned_calls'',''total_call'',''Last_visit' ;
      for m in 1..v_max_visit loop
          v_visit.extend;
          v_visit(m) := '';
          v_insert_col_head := v_insert_col_head || ''',''VISIT_' || m || '';

      end loop m;
      v_insert_col_head := v_insert_col_head || ''')';
      execute immediate v_insert_col_head;

    -------------------till here i am not getting any error 
      for a in al loop
        for c in (select distinct CCA_USER_ID,FLM,Ad_Sales,Client_Customer_id,Customer_name,Specialty,brand,class,Planned_calls,total_call,Last_visit from TMP_BMS_RPT_3 where employee_name = a.employee_name and team_name=a.team_name and employee_name  in('JAY DESAI')   order by 1) loop
          j := 1;

            v_insert_sql := 'insert into tmp_BMS_monthly_report (Team_name,CCA_USER_ID,EMPLOYEE_NAME,FLM,Ad_Sales,Client_Customer_id,Customer_name,Specialty,brand,Class,Planned_calls,total_call,Last_visit';
            v_insert_sql_val := ' VALUES (''' || a.team_name
                                  || ''', ''' || c.CCA_USER_ID
                                  || ''', ''' || a.EMPLOYEE_NAME
                                  || ''', ''' || c.FLM
                                  || ''', ''' || c.ad_sales
                                  || ''', ''' || c.Client_Customer_id
                                  || ''', ''' || c.Customer_name
                                  || ''', ''' || c.Specialty
                                  || ''', ''' || c.brand
                                  || ''', ''' || c.Class
                                  || ''', ''' || c.Planned_calls
                                  || ''', ''' || c.total_call
                                  || ''', ''' || c.Last_visit;


            for dt in (select distinct visit_date from TMP_BMS_RPT_3 where employee_name = a.employee_name and Customer_name=c.Customer_name and c.total_call=total_call and  employee_name in('JAY DESAI')  order by 1)
                   loop
                  v_visit(j) := dt.visit_date;
                  dbms_output.put_line(v_visit(j));
                  v_insert_sql := v_insert_sql || ',VISIT_' ||j ;
                  v_insert_sql_val := v_insert_sql_val || ''', ''' || v_visit(j);
                  j := j + 1;
            end loop dt;
           v_insert_sql := v_insert_sql || ')';
           v_insert_sql_val := v_insert_sql_val || ''')';
           v_insert_sql := v_insert_sql || v_insert_sql_val;
        --dbms_output.put_line(v_insert_sql);
          execute immediate v_insert_sql;
        end loop c;
      end loop a;
      commit;

    --exception
    -- when others then
    --    dbms_output.put_line(SQLCode || ' - ' || SQLERRM );
    end;
    /

1 个答案:

答案 0 :(得分:0)

你对类型varray vairable的赋值是错误的,varray赋值的工作方式类似于(1,2,3,4)列,你分配为行,所以不用担心你使用类型表而不是varray,请检查下面的例子: / p>

type v_dt is table of date index by binary_integer;
          v_visit v_dt ;