【发布时间】:2020-07-02 13:50:33
【问题描述】:
我正在尝试找出是否有办法在 Oracle 中批量收集到多级类型。下面的示例应该有助于解释我正在尝试做的概念。
有一个带有非规范化县镇列表的源表:
create table county_town (county varchar2(20), town varchar2(20));
insert into county_town values ('Surrey', 'Dorking');
insert into county_town values ('Surrey', 'Woking');
insert into county_town values ('Surrey', 'Guildford');
insert into county_town values ('Oxfordshire', 'Thame');
insert into county_town values ('Oxfordshire', 'Abingdon');
我想要做的是将它加载到一个看起来像这样的多级类型中:
create type towns_typ as table of varchar2(20);
create type counties_typ as object (country varchar2(20), towns towns_type);
create type nt_counties_typ as table of counties_typ;
l_county_data nt_counties_typ
有没有什么方法可以写一个 SELECT 语句来批量收集这些数据到 l_county_data 表中?如果无法使用 BULK COLLECT 是否有另一种方法可以简单地做到这一点?
【问题讨论】: