oracle交换分区的操作步骤如下: 1. 创建分区表t1,假设有2个分区,p1,p2.2. 创建基表t11存放p1规则的数据。3. 创建基表t12 存
oracle交换分区的操作步骤如下:
1. 创建分区表t1,假设有2个分区,p1,p2.
2. 创建基表t11存放p1规则的数据。
3. 创建基表t12 存放p2规则的数据。
4. 用基表t11和分区表t1的p1分区交换。 把表t11的数据放到到p1分区
5. 用基表t12 和分区表t1p2 分区交换。 把表t12的数据存放到p2分区。
----1.未分区表和分区表中一个分区交换
create table t1
(
sid int not null primary key,
sname varchar2(50)
)
partition by range(sid)
( partition p1 values less than (5000) tablespace test,
partition p2 values less than (10000) tablespace test,
partition p3 values less than (maxvalue) tablespace test
) tablespace test;
sql> select count(*) from t1;
count(*)
----------
0
create table t11
(
sid int not null primary key,
sname varchar2(50)
) tablespace test;
create table t12
(
sid int not null primary key,
sname varchar2(50)
) tablespace test;
create table t13
(
sid int not null primary key,
sname varchar2(50)
) tablespace test;
--循环导入数据
declare
maxrecords constant int:=4999;
i int :=1;
begin
for i in 1..maxrecords loop
insert into t11 values(i,'ocpyang');
end loop;
dbms_output.put_line(' 成功录入数据! ');
commit;
end;
/
declare
maxrecords constant int:=9999;
i int :=5000;
begin
for i in 5000..maxrecords loop
insert into t12 values(i,'ocpyang');
end loop;
dbms_output.put_line(' 成功录入数据! ');
commit;
end;
/
declare
maxrecords constant int:=70000;
i int :=10000;
begin
for i in 10000..maxrecords loop
insert into t13 values(i,'ocpyang');
end loop;
dbms_output.put_line(' 成功录入数据! ');
commit;
end;
/
commit;
sql> select count(*) from t11;
count(*)
----------
4999
sql> select count(*) from t12;
count(*)
----------
5000
sql> select count(*) from t13;
count(*)
----------
60001
--交换分区
alter table t1 exchange partition p1 with table t11;
sql> select count(*) from t11; --基表t11数据为0
count(*)
----------
0
sql> select count(*) from t1 partition (p1); --分区表的p1分区数据位基表t11的数据
count(*)
----------
4999
alter table t1 exchange partition p2 with table t12;
select count(*) from t12;
select count(*) from t1 partition (p2);
alter table t1 exchange partition p3 with table t13;
select count(*) from t13;
select count(*) from t1 partition (p3);
,