Plsql ORA-06532:下标超出限制

Plsql ORA-06532:下标超出限制,plsql,sql-update,type-conversion,varray,Plsql,Sql Update,Type Conversion,Varray,事实上,我正在尝试更新1000条记录,每5000条记录我就提交一次。但是由于我对varray的限制,我得到了上面的错误。请提供阵列数据类型的备选方案,以便将100k键值存储为阵列!下面是代码示例 DECLARE v_initial number(6):=0; v_final number(6):=5000; -- TOtal number of records V_COUNT type lnum IS VARRAY(1000) OF INTEGER; -- change total n

事实上,我正在尝试更新1000条记录,每5000条记录我就提交一次。但是由于我对varray的限制,我得到了上面的错误。请提供阵列数据类型的备选方案,以便将100k键值存储为阵列!下面是代码示例

   DECLARE
v_initial number(6):=0;
v_final number(6):=5000;
 -- TOtal number of records V_COUNT 
type lnum IS VARRAY(1000) OF INTEGER; -- change total number of records
iid lnum;
v_maxnum number(8):=0;

BEGIN

iid:=lnum(); -- here 1000 values will be given 

v_maxnum := iid.count;
FOR i in v_initial..v_maxnum LOOP

    UPDATE table SET status='E' WHERE pkey=iid(i);

    IF i=v_final THEN
        COMMIT;
        v_initial:=v_final+1;
        v_final:=v_final+5000;
END IF;
IF i=v_maxnum THEN
         commit;
END IF;

    EXIT WHEN i= v_maxnum;


END LOOP;


END;
/

将v_initial初始化为1而不是0。Varray索引从1开始

另外,这里还有另一种技术,你可以简单地考虑每一个X记录:

commit_count_const CONSTANT number := 5000; -- commit every 5000
v_loop_counter := 0     
...
FOR i in...
  UPDATE...

  v_loop_counter := v_loop_counter + 1;     -- Increment counter

  -- If the remainder of the counter divided by commit_count_const is 0,
  --  then we hit a multiple of the commit_count so commit.
  IF MOD(v_loop_counter, commit_count_const) = 0 THEN
    COMMIT;
  end if;
...
END LOOP;

COMMIT;  -- commit to catch the rows updated since the last commit.
...
哦,别忘了添加错误处理,如果更新或提交失败怎么办