Oracle existing data large table to change the partition table

Create table, insert test data 

-- Create table
create table LXW_TEST
(
  CDATE DATE,
  T1    NUMBER,
  T2    VARCHAR2(2)
)
;

insert into lxw_test
  (cdate, t1, t2)
values
  (to_date('2020-07-01','yyyy-mm-dd'), 1, '01');


insert into lxw_test
  (cdate, t1, t2)
values
  (to_date('2020-07-02','yyyy-mm-dd'), 2, '02');

View data

Specific operation 

-- 根据原表结构创建分区表
create table LXW_TEST_2
(
  CDATE DATE,
  T1    NUMBER,
  T2    VARCHAR2(2)
) 
partition by range (cdate) ---分区的依据字段
 INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))  --自动增加分区的间隔
 (
  partition p1 values less than (to_date('2020-08-01', 'yyyy-mm-dd')) 
 )
tablespace tablespace_lxw
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table 
comment on table LXW_TEST
  is '测试表';
  
--交换分区
alter table LXW_TEST_2 exchange partition p1  with table LXW_TEST;

--分区重命名
alter table LXW_TEST rename to LXW_TEST_temp;
alter table LXW_TEST_2 rename to LXW_TEST;

--所有索引重建 

 Look at the query data

Look at the partition information

Insert a few pieces of data

insert into lxw_test
  (cdate, t1, t2)
values
  (to_date('2020-08-01', 'yyyy-mm-dd'), 3, '03');

insert into lxw_test
  (cdate, t1, t2)
values
  (to_date('2020-09-02', 'yyyy-mm-dd'), 4, '04');

insert into lxw_test
  (cdate, t1, t2)
values
  (to_date('2020-10-01', 'yyyy-mm-dd'), 5, '05');

 Query data

View partition information

 

Guess you like

Origin blog.csdn.net/lw112190/article/details/107949299