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 這種寫法是可以多進程同時查看數據,效率要比普通查看效果快的多,但不可在程序中這樣寫,因為它會獨占進程,多人同時查看的話會比普通方法還要慢。