oracle分割槽表學習及應用

2021-03-31 08:56:28 字數 2974 閱讀 9149

-- 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 (200408)

tablespace ts_ziken

storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0),

partition p_200408 values less than (200409)

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 local;

grant all on bill_monthfee_zero to dxsq_dev;

--增加分割槽表

alter table bill_monthfee_zero add partition p_200409

values less than (200410) 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);

--合併分割槽

altertablebill_monthfee_zero

mergepartitions p_200408

,p_200409 intopartitionp_all

--將分割槽改名

altertablebill_monthfee_zero rename partitionp_200408 top_fee_200408

--將分割槽改表空間

altertablebill_monthfee_zero move partitionp_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=scott/tiger@aaa

buffer=102400

tables=bill_monthfee:p_200401,

file=e:/exp_para/exp_dxsq_tables.dmp

log=e:/exp_para/exp_dxsq_tables.log

乙個表加入到乙個分割槽表中當作是乙個分割槽子表例子

--清空11月份資料.

alter table bill_monthfee truncate partition p_200311; /

--防止操作出錯,先把原表備份.

create table tmp_bill_monthfee_2311 as select * from tmp_bill_monthfee_200311;

--把備份的表新增到原表中,這時備份表的記錄為0

alter table bill_monthfee exchange partition p_200311 with table tmp_bill_monthfee_200311 /

--重建11月份的索引.

alter index idx_bill_monthfee_01 rebuild partition p_200311 nologging  /

alter index idx_bill_monthfee_acc_id rebuild partition p_200311 nologging /

alter index idx_bill_monthfee_serv_id rebuild partition p_200311 nologging

注意:把錶加入到分割槽表中,此表的結構與分割槽表要一致,而且匯入後這個表的記錄都沒了.

技巧:

刪除表中乙個字段:

alter table bill_monthfee_zero set unused column date_type;

新增乙個字段:alter table bill_monthfee_zero add date_type number(1);

oracle分割槽表學習及應用

oracle 分割槽表學習及應用 create table 建立分割槽表 create table bill monthfee zero serv id number 20 not null,billing cycle month number 6 not null,date type number...

oracle分割槽表學習及應用

oracle 分割槽表學習及應用 create table 建立分割槽表 create table bill monthfee zero serv id number 20 not null,billing cycle month number 6 not null,date type number...

Oracle分割槽表學習及練習

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 varcha...