Oracle 分区表常用SQL语句 (转载)

来源:互联网 发布:山西省经信委大数据 编辑:程序博客网 时间:2024/05/21 22:31

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zliu789/archive/2009/03/10/3976621.aspx

 

*********
为分区表建立一个单独的表空间
*********/create tablespace ts_partition datafile '/home/oracle/oradata/esales/partition.dbf' size 10M
extent management local uniform size 2M;

/*********
建立分区表
*********/create table bigtable
(
sale_date date,
product_id number,
sale_count number,
charge number,
sales_id number
)
tablespace ts_partition
pctfree 5
pctused 80
initrans 1
maxtrans 255
parallel(degree 2)
storage
(
initial 2M
next 2M
minextents 1
maxextents unlimited
pctincrease 0
)
partition by range(sale_date)
(
partition sale_date_20020101 values less than (to_date('20020102','yyyymmdd')),
partition sale_date_20020102 values less than (to_date('20020103','yyyymmdd'))
);

/*********
建立分区索引
*********/create index create index idx_bigtable_product_id on bigtable(product_id) parallel 2 local
tablespace users on bigtable(product_id) parallel 2 local tablespace users;

/*********
增加分区
*********/alter table bigtable add partition sale_date_20020103
values less than (to_date('20020104','yyyymmdd'));

/*********
截断分区
*********/alter table bigtable truncate partition sale_date_20020103;

/*********
丢弃分区
*********/alter table bigtable drop partition sale_date_20020103;

/*********
交换分区
如果分区表里含有 LOCAL 的索引,此分区的索引将处于不可用状态,需要重建:
alter index idx_bigtable_product_id rebuild partition sale_date_20020102 tablespace users;
如果被交换表和分区表的索引结构相同,可以用 including indexes 连同索引一起交换,不必重建索引。
*********/create table bigtable_temp tablespace users as select * from bigtable where 1=2;
insert into bigtable_temp values (to_date('20020102','yyyymmdd'),1,10,1,10);
commit;
alter table bigtable exchange partition sale_date_20020102 with table bigtable_temp;

/*********
移动分区
*********/alter table bigtable move partition sale_date_20020102 tablespace user2;

/*********
修改分区
*********/alter table bigtable modify partition
sale_date_20020102 storage(pctincrease 10);

/*********
重命名分区
*********/alter table bigtable rename partition
sale_date_20020102 to sale_date_20020103;

/*********
分割分区
*********/alter table bigtable add partition sale_date_20020104
values less than (to_date('20020105','yyyymmdd'));
alter table bigtable split partition sale_date_20020104
at (to_date('20020104','yyyymmdd'))
into (partition sale_date_20020103,partition sale_date_20040104);

/*********
分区表数据的逻辑备份
exp username/password file=bigtable20020103_4.dmp tables=(bigtable:sale_date_20020103,bigtable:sale_date_20020104)
分区表数据的逻辑恢复
imp username/password file=bigtable20020103_4.dmp tables=(bigtable:sale_date_20020103,bigtable:sale_date_20020104) ignore=y
*********/

 

原创粉丝点击