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

*********
为分区表建立一个单独的表空间
*********/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
*********/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值