1


我想在 Oracle 中从几千个点构建形状,但是在运行创建的代码时,我得到了错误:

ORA-06550: 程序太大(代码生成操作数)

我达到了什么极限?我该如何克服它?
重现错误的类似代码(它会在一分钟内运行或失败):

declare
  s clob;
begin
  s := '
    declare
       type t_x is table of number index by pls_integer;
       x t_x;
       varr sdo_ordinate_array;
    begin
    ';
  for i in 1..23000 loop --21825: ok, 21850: error
     s := s || 'x('||to_char(i)||') := 46.709864 + '||to_char(i)||'/23000;';
  end loop;

  s := s || '
      varr := sdo_ordinate_array();
      varr.extend(x.count);

      for i in 1 .. x.count loop
         varr(i) := x(i);
      end loop;
    end;';
  execute immediate s;
end;
4

2 回答 2

1

将所有内容都放在一个动态语句中是有原因的吗?看起来真的很奇怪。

尝试类似这样:

declare
    varr sdo_ordinate_array;
begin
    varr := sdo_ordinate_array();
    for i in 1..23000 loop
        varr.extend;
        varr(i) := 46.709864 + i/23000;
    end loop;   

end;

我不知道你的真实代码,但你也可以从执行立即返回值作为这个例子。也许它可以简化您的问题。

DECLARE
    type t_x is table of number index by pls_integer;
    x t_x;
    str varchar2(100);
BEGIN
    FOR i in 10..20 LOOP
        str := i|| ' * 2';
        EXECUTE IMMEDIATE 'BEGIN :ret := '||str||'; END;' USING OUT x(i);
        dbms_output.put_line(x(i));
    END LOOP;
END;
于 2017-09-01T13:22:23.523 回答
0

看来,批量收集可以解决这个问题。以下代码运行时间延长了 10 倍,但没有报错:

declare
  s clob;
begin
  s := '
    declare
       type t_x is table of number index by pls_integer;
       x t_x;
       varr sdo_ordinate_array;
    begin
       select coord 
       bulk collect into x
       from (';
  for i in 1..23000 loop --21825: ok, 21850: error
     s := s || 'select '||to_char(i)||' rn, 46.709864 + '||to_char(i)||'/23000 coord from dual union all'||chr(10);
  end loop;

  s := s || '
      select null,null from dual
      )
      where rn is not null
      order by rn;

      varr := sdo_ordinate_array();
      varr.extend(x.count);

      for i in 1 .. x.count loop
         varr(i) := x(i);
      end loop;
    end;';
  execute immediate s;
end;
于 2017-09-01T13:15:45.923 回答