oracle分区表和非分区表exchange

时间:2024-03-18 22:42:17

1 创建分区表emp2

   CREATE TABLE emp2
    (empno NUMBER(4) NOT NULL,
    ename VARCHAR2(10),
    sal NUMBER(7))
    PARTITION BY RANGE(ename)
    (partition emp2_p1 VALUES LESS THAN ('D'),
   partition emp2_p2 VALUES LESS THAN ('Q'),
    partition emp2_p3 VALUES LESS THAN (MAXVALUE)
   );

2 创建普通表emp_tmp

 create table emp_tmp
  (
  empno NUMBER(4) NOT NULL,
  ename VARCHAR2(10),
  sal NUMBER(7)
   );

3 往表中插入数据

insert into emp2 values(1,'Andy',575);
insert into emp2 values(2,'Derek',570);
insert into emp2 values(3,'Patrick',590);
insert into emp2 values(4,'Richard',400);
insert into emp_tmp values(5,'Heidi',666);

4 将emp2的emp2_p2分区和普通表emp_tmp进行交换

alter table emp2 exchange partition emp2_p2  with table emp_tmp;