dbalearner
Technical User
I have been given a sample code to test. The code is as follows:
create table t as select * from (select * from all_objects order by dbms_random.random);
alter table t add constraint t_pk primary key (object_id;
1 declare
2 type array is table of t%rowtype index by binary_integer;
3 l_data array;
4 l_rec t%rowtype;
5 begin
6 select object_id bulk collect into l_data from all_objects;
7 for i in 1 .. l_data.count
8 loop
9 select * into l_rec from t where object_id = l_data(i);
10 end loop;
11* end;
mich@MYDB.MICH.LOCAL> /
select object_id bulk collect into l_data from all_objects;
*
ERROR at line 6:
ORA-06550: line 6, column 45:
PL/SQL: ORA-00913: too many values
ORA-06550: line 6, column 3:
PL/SQL: SQL Statement ignored
ORA-06550: line 9, column 51:
PLS-00382: expression is of wrong type
When I replace line 6 as follows:
6 select * bulk collect into l_data from all_objects;
I get the following:
1 declare
2 type array is table of t%rowtype index by binary_integer;
3 l_data array;
4 l_rec t%rowtype;
5 begin
6 select * bulk collect into l_data from all_objects;
7 for i in 1 .. l_data.count
8 loop
9 select * into l_rec from t where object_id = l_data(i);
10 end loop;
11* end;
mich@MYDB.MICH.LOCAL> /
select * into l_rec from t where object_id = l_data(i);
*
ERROR at line 9:
ORA-06550: line 9, column 51:
PLS-00382: expression is of wrong type
Any help is appreciated.
Thanks
create table t as select * from (select * from all_objects order by dbms_random.random);
alter table t add constraint t_pk primary key (object_id;
1 declare
2 type array is table of t%rowtype index by binary_integer;
3 l_data array;
4 l_rec t%rowtype;
5 begin
6 select object_id bulk collect into l_data from all_objects;
7 for i in 1 .. l_data.count
8 loop
9 select * into l_rec from t where object_id = l_data(i);
10 end loop;
11* end;
mich@MYDB.MICH.LOCAL> /
select object_id bulk collect into l_data from all_objects;
*
ERROR at line 6:
ORA-06550: line 6, column 45:
PL/SQL: ORA-00913: too many values
ORA-06550: line 6, column 3:
PL/SQL: SQL Statement ignored
ORA-06550: line 9, column 51:
PLS-00382: expression is of wrong type
When I replace line 6 as follows:
6 select * bulk collect into l_data from all_objects;
I get the following:
1 declare
2 type array is table of t%rowtype index by binary_integer;
3 l_data array;
4 l_rec t%rowtype;
5 begin
6 select * bulk collect into l_data from all_objects;
7 for i in 1 .. l_data.count
8 loop
9 select * into l_rec from t where object_id = l_data(i);
10 end loop;
11* end;
mich@MYDB.MICH.LOCAL> /
select * into l_rec from t where object_id = l_data(i);
*
ERROR at line 9:
ORA-06550: line 9, column 51:
PLS-00382: expression is of wrong type
Any help is appreciated.
Thanks