PL SQL中循环内的varray初始化

时间:2014-09-11 15:06:10

标签: oracle plsql oracle11g

我想知道在循环内的每次迭代中初始化varray集合时内存中发生了什么,如下例所示:

Declare 
  Cursor cuEmployees Is
    Select id, first_names, last_names
    From   employees
    Order by is;
  Cursor cuNom1(xId_employee employees.id%Type) Is
    Select salary, dependency
    From   nom1.payments
    Where  id_employee = xId_employee;
  Cursor cuNom2(xId_employee employees.id%Type) Is
    Select salary, dependency
    From   nom2.payments
    Where  id_employee = xId_employee;
  Cursor cuNom3(xId_employee employees.id%Type) Is
    Select salary, dependency
    From   nom3.payments
    Where  id_employee = xId_employee;        
  Type nomVarray Is Varray(3) Of cuNom1%Rowtype;
  nomPayments nomVarray;
  va_nuIndex  Integer;
  regPayment  cuNom1%Rowtype;
Begin

  For cu In cuEmployees Loop
    -- Initialize variables per employee.
    va_nuIndex  := 0;
    nomPayments := nomVarray(Null, Null, Null); /* What happen on memory if I do that on every iteration? */
    -- Load info of payments 1.
    va_nuIndex := va_nuIndex + 1;
    Open  cuNom1(cu.numidemp);
    Fetch cuNom1 Into nomPayments(va_nuIndex);
    If (cuNom1%NotFound) Then
      nomPayments(va_nuIndex) := Null;;
    End If;      
    Close cuNom1;
    -- Load info of payments 2.
    va_nuIndex := va_nuIndex + 1;
    Open  cuNom2(cu.numidemp);
    Fetch cuNom2 Into nomPayments(va_nuIndex);
    If (cuNom2%NotFound) Then
      nomPayments(va_nuIndex) := Null;;
    End If;      
    Close cuNom2;
    -- Load info of payments 3.
    va_nuIndex := va_nuIndex + 1;
    Open  cuNom3(cu.numidemp);
    Fetch cuNom3 Into nomPayments(va_nuIndex);
    If (cuNom3%NotFound) Then
      nomPayments(va_nuIndex) := Null;;
    End If;      
    Close cuNom3;
    -- Function that compares info of the payments, select and return what record need to use.
    regPayment := FunctionComparePayments(nomPayments);
    -- ...
  End Loop;
End;

内存会发生什么?实例为循环上的每次迭代在内存上创建一个新对象,或者只在内存中使用相同的对象。

知道影响表现吗?

感谢,

1 个答案:

答案 0 :(得分:0)

其实你的问题本身就错了!

初始化与内存无关。 Oracle需要一个缓冲区来存储获取的行,而不是在初始化时。这些是基本概念。