一括収集を使用して、%rowtype の複数のフィールドを持つレコードのテーブルを作成するにはどうすればよいですか?
私のコード:
drop table child_table;
drop table parent_table;
/
create table parent_table(pk number primary key);
create table child_table(pk number primary key, fk REFERENCES parent_table(pk));
/
insert into parent_table (pk) values (1);
insert into parent_table (pk) values (2);
insert into child_table (pk, fk) values (11, 1);
insert into child_table (pk, fk) values (21, 1);
insert into child_table (pk, fk) values (32, 2);
/
declare
type rec is record
(
parent parent_table%rowtype,
child child_table%rowtype
);
type tbl is table of rec;
v_table tbl := tbl();
-- this works
type tbl_parent is table of parent_table%rowtype;
v_parent_table tbl_parent := tbl_parent();
begin
-- this works
select * bulk collect into v_parent_table from parent_table;
-- this doesn't work
select * bulk collect into v_table from parent_table parent
inner join child_table child on parent.pk = child.fk;
end;
このコードは機能しませんが、次のエラー メッセージがスローされます。
ORA-06550: line 13, column 30:
PLS-00597: expression 'V_TABLE' in the INTO list is of wrong type
ORA-06550: line 13, column 30:
PLS-00597: expression 'V_TABLE' in the INTO list is of wrong type
ORA-06550: line 13, column 38:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 13, column 3:
PL/SQL: SQL Statement ignored
わかりました、オラクルは私が間違ったデータ型を使用していると言い、私は同意します。しかし、それを修正する方法は?