分区表的通俗解释:
普通表呢像一个小学生用的新华字典,分区表呢像一套博士们辞海,在同一个漂亮的盒子里面(表名)有若干本辞海分册(每一册就是一个分区了)。
如果说检索一张普通表就像查新化字典,检索分区表就像查辞海了。具体而言呢,又这么几种方式:
1).
因为你知道你查的内容只会出现在某些分册里面,于是你很快的从辞海盒子里面取出你要的那个册子,不加思索的翻到索引页,根据索引页的指示,你飞快的翻到你的目标页面。取一本本册子呢就叫partition
range [inlist] iterator,找索引页当然就是index range scan。如果你不找索引页,准备翻完整本书的找,那就是full
table scan了。如果你只找一本册子的,那partition range iterator也就不必了。
2).
哦,你不知道你要查的内容在那本册子里? 那你只好辛苦一点,翻阅所有册子了。这时,你做的动作就叫partition range all.
而对于每本册子言,也许你会找索引页(index scan),也许你想翻遍全册(full table scan)。
3).
也许你发现一册册的打开索引页找内容太繁重了,你突然想起来对你的辞海做个整改。于是你把每册的索引页全都拆了下来,专门装订成一册。每次你想利用索引页找东西时,你就打开这个索引册。从索引册,你就可以找到你要内容在哪一册哪个地方。这就是global
index scan. 相对于1,2,就叫local index scan.
4).
你有儿子吗?有一天,你想培训儿子的能力,于是你就找来你儿子给你翻册子,找资料。可是你儿子非得和老子一起找才肯帮你。于是你们父子俩就开始一起检索起辞海来,你查某些册子,他查另一些册子。这就叫partition
scan.
-- Create table(创建分区表)
create table
BILL_MONTHFEE_ZERO
(
SERV_ID NUMBER(20) not null,
BILLING_CYCLE_MONTH
NUMBER(6) not null,
DATE_TYPE NUMBER(1),
ACC_NBR
VARCHAR2(80)
)
partition by range (BILLING_CYCLE_MONTH)
(partition
p_200407 values less than (200407)
tablespace TS_ZIKEN
storage(initial
100k next 100k minextents 1 maxextents unlimited pctincrease 0),
partition
p_200408 values less than (200408)
tablespace TS_ZIKEN
storage(initial
100k next 100k minextents 1 maxextents unlimited pctincrease 0))
;
create
index idx_bill_monthfee_zero_idx01 on
bill_monthfee_zero(billing_cycle_month)
tablespace
TS_ZIKEN_idx
storage(initial 100k next 100k minextents 1 maxextents unlimited
pctincrease 0) nologging;
grant all on bill_monthfee_zero to
dxsq_dev;
--增加分区表
alter table BILL_MONTHFEE_ZERO add Partition
p_200409
values less than (200409) tablespace
ts_ziken;
--删除一分区
alter table part_tbl drop Partition
part_tbl_08;
--将一个分区分为两个分区
alter table bill_monthfee_zero split Partition
p_200409 at (200409)
into (Partition p_200409_1 tablespace
ts_ziken,
Partition p_200409_2 tablespace ts_ziken_idx);
--合并分区
ALTER
TABLE bill_monthfee_zero
MERGE PARTITIONS p_200408, p_200409 INTO PARTITION
p_all
--将分区改名
alter table bill_monthfee_zero rename Partition p_200408 to
p_fee_200408
--将分区改表空间
alter table bill_monthfee_zero move Partition
p_200409
tablespace ts_ziken_01 nologging
--查询特定分区
select count(*) from
BILL_MONTHFEE_ZERO partition (p_200407);
--添加数据
insert into
bill_monthfee_zero select * from bill_monthfee_zero partition
(p_200407)
--分区表的导出
userid=dxsq/teledoone@jndxsq154
buffer=102400
tables=bill_monthfee:P_200401,
file=E:exp_paraexp_dxsq_tables.dmp
log=E:exp_paraexp_dxsq_tables.log
--exchange
partition:
交换分区是将一个分区的数据和一个非分区的表数据进行数据交换。条件是两者逻辑结构相同,而且表数据的数据不能超出分区主键的范围,否则:
SQL>
alter table baisadmin.t_name exchange partition p5 with table
baisadmin.t_n
ame_check_reg;
alter table baisadmin.t_name exchange
partition p5 with table baisadmin.t_name_bak
技巧:
删除表中一个字段:
alter table
bill_monthfee_zero set unused column date_type;
添加一个字段:alter table
bill_monthfee_zero add date_type number(1);
[@more@]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9650775/viewspace-923219/
,如需转载,请注明出处,否则将追究法律责任。