ORA-06532:下限超出限制

时间:2014-12-05 11:01:19

标签: 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 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;
/

1 个答案:

答案 0 :(得分:0)

将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.
...

哦,不要忘记添加错误处理,如果UPDATE或COMMIT失败怎么办?