分区交换 技术

分区交换,可以实现,普通表和分区表的某个分区之间的数据交换,它们之间的交换非常快。


/**====================================================================*/
select t.table_name , t.owner  from ALL_PART_TABLES t  where t.owner = 'SCOTT';  
select t.table_name ,t.partitioning_type,t.partition_count  from  USER_PART_TABLES  t;  
select t.table_name,t.table_owner,t.partition_name ,t.partition_position from DBA_TAB_PARTITIONS t  
where t.table_owner = 'SCOTT'and t.table_name = upper('range_part_tab') ;  

--获取2016年的数据
select count(*)  from range_part_tab  partition (PAR_LIST_MAX) ;

drop table target_exchange_tab purge;

create table target_exchange_tab 
as
select *  from range_part_tab 
where 2 = 1; 

--查看目标表是否有索引
select count(*) from user_indexes T 
 where table_name= upper('target_change_tab') ;

 
--将该数据和目标表进行交换
alter table range_part_tab exchange partition PAR_LIST_MAX with table target_exchange_tab ;

select count(*)  from range_part_tab  partition (PAR_LIST_MAX) ;
select count(*)  from target_exchange_tab ; 


--再执行一次 ,数据就回来了
alter table range_part_tab exchange partition PAR_LIST_MAX with table target_exchange_tab ;

select count(*)  from range_part_tab  partition (PAR_LIST_MAX) ;
select count(*)  from target_exchange_tab ; 


--复制
truncate table target_exchange_tab ; 

insert into target_exchange_tab
select *  from range_part_tab  partition (PAR_LIST_MAX) where rownum <= 1000;
commit;


select count(*)  from range_part_tab  partition (PAR_LIST_MAX) ;
select count(*)  from target_exchange_tab ; 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值