历史数据转换性能优化的一种方式

一张表几个亿的数据,需要按年份切分,还有转换逻辑,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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值