a) it would be syntatically nice, yes, but until then -- see
</code>
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:3239385496862 <code>
it shows how to do this in a two step
b) you would have to use a record of arrays instead of an array of records. It has to do with how the data is physically organized (row major or column major) in the array. Array operations work on contigous arrays.
For example:
ops$tkyte@ORA920.US.ORACLE.COM> create table t ( x int, y int );
Table created.
ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> declare
2 type foo is record
3 ( x int,
4 y int
5 );
6
7 type foo_array is table of foo index by binary_integer;
8
9 l_data foo_array;
10 begin
11 for i in 1 .. 2
12 loop
13 l_data(i).x := i;
14 l_data(i).y := i;
15 end loop;
16
17 forall i in 1 .. 2
18 insert into t values l_data(i);
19 end;
20 /
PL/SQL procedure successfully completed.
so, in some cases, we can use arrays of records -- when the interface is expecting a record at a time.... (using new 9ir2 feature to insert/update using RECORDSops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> declare
2 type foo is record
3 ( x int,
4 y int
5 );
6
7 type foo_array is table of foo index by binary_integer;
8
9 l_data foo_array;
10 begin
11 for i in 1 .. 2
12 loop
13 l_data(i).x := i;
14 l_data(i).y := i;
15 end loop;
16
17 forall i in 1 .. 2
18 update t set y = l_data(i).y where x = l_data(i).x;
19 end;
20 /
update t set y = l_data(i).y where x = l_data(i).x;
*
ERROR at line 18:
ORA-06550: line 18, column 26:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records
ORA-06550: line 18, column 35:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 18, column 9:
PL/SQL: SQL Statement ignored
but because of the row major organization of the array here -- the elements of y are not contigous, hence we cannot use the array on Y or X..ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> declare
2 type intArray is table of int index by binary_integer;
3 type foo is record
4 ( x intArray,
5 y intArray
6 );
7
8 l_data foo;
9 begin
10 for i in 1 .. 2
11 loop
12 l_data.x(i) := i;
13 l_data.y(i) := i;
14 end loop;
15
16 forall i in 1 .. 2
17 update t set y = l_data.y(i) where x = l_data.x(i);
18 end;
19 /
PL/SQL procedure successfully completed.
but here we can..