oracle分割槽表和分割槽表exchange

a960549548發表於2024-03-15

查詢分割槽表分割槽內容

select * from emp2 partition(emp2_p3);


1 建立分割槽表 emp1

CREATE TABLE emp1
(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 建立分割槽表 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)
);

3 建立非分割槽表

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

create table emp_test  as select * from emp1 where 1=0;(建立emp_test表和emp1表結構一樣但沒有資料)
create table emp_test  as select * from emp1;(建立emp_test表和emp1一模一樣)


4 插入資料

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 emp1 values(5,'Heidi',666);

5 emp2_p2 emp1_p2 透過 emp_tmp 進行交換

alter table emp2 exchange partition emp2_p2  with table emp_tmp UPDATE GLOBAL INDEXES;
alter table emp1 exchange partition emp2_p2 with table emp_tmp UPDATE GLOBAL INDEXES;
alter table emp2 exchange partition emp2_p2  with table emp_tmp UPDATE GLOBAL INDEXES;


來自 “ ITPUB部落格 ” ,連結:https://blog.itpub.net/70013625/viewspace-3009039/,如需轉載,請註明出處,否則將追究法律責任。

相關文章