Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually initialize a collection of RECORDs in PL/SQL?

guys. Here's a simple sample two-dimensional array in PL/SQL, which is working perfectly.

declare
  type a is table of number;
  type b is table of a;

  arr b := b(a(1, 2), a(3, 4));
begin
  for i in arr.first .. arr.last loop
    for j in arr(i).first .. arr(i).last loop
      dbms_output.put_line(arr(i) (j));
    end loop;
  end loop;
end;

What I need to do, is to create something similar for a table of RECORDS. Like this:

 type a is record(a1 number, a2 number);
 type b is table of a;

The question is, can I manually initialize this kind of array, or it is supposed to be filled by bulk collects or similar? The same syntax as above doesn't seem to work, and I wasn't able to find any initialization sample in manuals.

like image 319
Kirill Leontev Avatar asked Sep 14 '10 08:09

Kirill Leontev


1 Answers

There is no "constructor" syntax for RECORDs, so you have to populate them like this:

declare
 type a is record(a1 number, a2 number);
 type b is table of a;
 arr b := b();
begin
 arr.extend(2);
 arr(1).a1 := 1;
 arr(1).a2 := 2;
 arr(2).a1 := 3;
 arr(2).a2 := 4;
end;
like image 146
Tony Andrews Avatar answered Sep 29 '22 05:09

Tony Andrews