1.查看该分区有无数据
select /*+ parallel(a 16) */ count(1) from ZJ2_GRIDLEVSTA_cell_ALL_571 partition(SYS_P16805) a --where a.p_day=to_date('20171231','yyyymmdd');
2.如果分区表里有主键,自增列,删掉
alter table zj2_gridlevsta_all_571 drop primary key; drop index PK_ZJ2_GRIDLEVSTA_ALL_571_OID; alter table ZJ2_GRIDLEVSTA_CELL_ALL_571 modify oid drop identity;
3.创建表,保证索引,非空约束与分区表一致
create table ZJ2_GRIDLEVSTA_cell_ALL_571_b as select * from ZJ2_GRIDLEVSTA_cell_ALL_571 where 1=2; alter table ZJ2_GRIDLEVSTA_CELL_ALL_571_b modify oid not null; create index b_ECI_INDEX on ZJ2_GRIDLEVSTA_CELL_ALL_571_b (ECI);
4.分区表和非分区表 交换分区
alter table ZJ2_GRIDLEVSTA_cell_ALL_571 exchange partition SYS_P16805 with table ZJ2_GRIDLEVSTA_cell_ALL_571_b;
注意:要交换的分区表中不能含有自增列,主键,否则可能无法交换分区
select /*+ parallel(a 16) */ count(1) from 这种写法是可以多进程同时查看数据,效率要比普通查看效果快的多,但不可在程序中这样写,因为它会独占进程,多人同时查看的话会比普通方法还要慢。