一张表几个亿的数据,需要按年份切分,还有转换逻辑,insert all派上用场了。
drop table t_source purge;
drop table t_target_2019 purge;
drop table t_target_2020 purge;
drop table t_target_2021 purge;
create table t_source (id number, create_time date);
create table t_source_detail (id number, name varchar2(100));
create table t_target_2019 (id number, create_time date,name varchar2(100));
create table t_target_2020 (id number, create_time date,name varchar2(100));
create table t_target_2021 (id number, create_time date,name varchar2(100));
insert into t_source values(1, to_date(‘2019-01-01’,‘yyyy-mm-dd’));
insert into t_source values(2, to_date(‘2020-01-01’,‘yyyy-mm-dd’));
insert into t_source values(3, to_date(‘2021-01-01’,‘yyyy-mm-dd’));
insert into t_source_detail values(1, ‘aa’);
insert into t_source_detail values(2, ‘bb’);
insert into t_source_detail values(3, ‘cc’);
commit;
insert all
when create_time < to_date(‘2020-01-01’,‘yyyy-mm-dd’) then into t_target_2019(id, create_time,name)
when create_time < to_date(‘2021-01-01’,‘yyyy-mm-dd’) and create_time >= to_date(‘2020-01-01’,‘yyyy-mm-dd’)
then into t_target_2020(id, create_time,name)
when create_time < to_date(‘2022-01-01’,‘yyyy-mm-dd’) and create_time >= to_date(‘2021-01-01’,‘yyyy-mm-dd’)
then into t_target_2021(id, create_time,name)
select a.id,a.create_time,b.name from t_source a ,t_source_detail b where a.id = b.id;
commit;
select * from t_target_2019;
select * from t_target_2020;
select * from t_target_2021;