如何使用批量收集填充具有多个 %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
好吧,oracle 说我使用了错误的数据类型,我同意。但如何解决呢?