Oracle程序太大(codegen operands)错误

时间:2017-09-01 13:03:53

标签: oracle codegen


我希望从几千个点在Oracle中构建形状,但在运行创建的代码时,我收到错误:

  

ORA-06550:程序太大(codegen操作数)

我打的限制是什么?我怎样才能克服它? 用于重现错误的类似代码(它在一分钟内运行或失败):

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;

2 个答案:

答案 0 :(得分:1)

有没有理由将所有内容都放在一个动态语句中?看起来很奇怪。

尝试类似于此:

Function PivotTable()
Dim Data_sht As Worksheet
Dim Pivot_sht As Worksheet
Dim StartPoint As range
Dim DataRange As range
Dim PivotName As String
Dim NewRange As String

'Set Variables Equal to Data Sheet and Pivot Sheet
 Set Data_sht = ThisWorkbook.Worksheets("Sheet1")
 Set Pivot_sht = ThisWorkbook.Worksheets("Pivot Table")

'Enter in Pivot Table Name
 PivotName = "PivotTable"

'Dynamically Retrieve Range Address of Data
 Set StartPoint = Data_sht.range("A1")
 Set DataRange = Data_sht.range(StartPoint, StartPoint.SpecialCells(xlLastCell))

NewRange = Data_sht.Name & "!" & _
DataRange.Address(ReferenceStyle:=xlR1C1)

'Make sure every column in data set has a heading and is not blank (error prevention)
  If WorksheetFunction.CountBlank(DataRange.Rows(1)) > 0 Then
MsgBox "One of your data columns has a blank heading." & vbNewLine _
  & "Please fix and re-run!.", vbCritical, "Column Heading Missing!"
End If

'Change Pivot Table Data Source Range Address
 Pivot_sht.PivotTables(PivotName).ChangePivotCache _
ThisWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=NewRange)

'Ensure Pivot Table is Refreshed
 Pivot_sht.PivotTables(PivotName).RefreshTable


 End Function

我不知道您的真实代码,但您也可以在此示例中从execute immediate返回值。也许它可以简化你的问题。

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;

答案 1 :(得分: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;