Oracle資料分割槽

2021-09-01 08:29:05 字數 2815 閱讀 7203

--範圍分割槽

--範圍分割槽就是對資料表中的某個值的範圍進行分割槽,根據某個值的範圍,決定將該資料儲存在哪個分割槽上。如根據序號分割槽,根據業務記錄的建立日期進行分割槽等

create table subarea

( pid number not null,

pitem varchar2(200),

pdata date not null

) partition by range(pid)

( partition part_01 values less than(100000),

partition part_02 values less than(200000),

partition part_03 values less than(300000),

partition part_04 values less than(400000),

partition part_05 values less than(maxvalue)

) --新增分割槽

alter table subarea drop partition part_01;

alter table subarea drop partition part_02;

alter table subarea drop partition part_03;

alter table subarea drop partition part_04;

alter table subarea drop partition part_05;

alter table subarea add partition part_03 values less than(200000)

alter table subarea add partition part_04 values less than(300000)

alter table subarea add partition part_05 values less than(maxvalue)

--更改分割槽名

alter table subarea rename partition part_01 to part_01_01;

--合併分割槽

alter table subarea merge partitions part_01,part_02 into partition part_02;

--拆分分割槽

alter table subarea split partition part_03 at(250000) into (partition part_03_01,partition part_03_02);

select t.*,t.rowid from subarea partition(part_01) t where t.pid<50000 order by t.rowid

select * from subarea partition(part_02) where pid<100000 order by pid

select * from subarea partition(part_03) where pid>50000 order by pid

select max(pid) from subarea

--hash 分割槽技術

--雜湊分割槽為通過指定分割槽編號來均勻分布資料的一種分割槽型別,因為通過在i/o裝置上進行雜湊分割槽,使得這些分割槽大小一致。

create table subarea_hash

( pid number not null,

pitem varchar2(200),

pdata date not null

) partition by hash(pid)

( partition part_h01,

partition part_h02,

partition part_h03

) insert into subarea_hash(pid,pitem,pdata) select pid ,pitem,pdata from subarea

select t.*,t.rowid from subarea_hash partition(part_h02) t order by pid

select t.*,rownum from subarea partition(part_03_01) t

---復合分割槽

create table subarea_fh

( pid number not null,

pitem varchar2(200),

pdata date not null

) partition by range(pid)

subpartition by hash(pid)

( partition part_r01 values less than (100000)

(subpartition part_r01_01,

subpartition part_r01_02

), partition part_r02 values less than (200000),

partition part_r03 values less than (maxvalue)

(subpartition part_r03_01,

subpartition part_r03_02 ))

select t.*,t.rowid from subarea_fh subpartition(part_r01_01) t order by pid;

select t.*,t.rowid from subarea_fh subpartition(part_r01_02) t order by pid

oracle資料庫分割槽

numtoyminterval和numtoyminterval是日期轉換函式,作用 可以將數字轉換成相應的日期單位時間 1.numtoyminterval n char expr char expr 日期描述,可以是year和month。通常當我們使用add month新增月時,如果輸入是本月月底的...

oracle資料庫表分割槽

最近偶然有聽到資料庫表分割槽的概念,一時興趣來潮,就想去稍微了解下。對於我們一些專案,可能我們需要接入一些資料,時間越長,資料量就越多,資料庫表訪問就越慢。這時候適量的分割槽有助於提高資料庫表的訪問速度。一 首先說說比較常用的集中分割槽方法 範圍分割槽 時間分割槽 create table data...

Oracle資料庫的分割槽

實現了均勻的負載值分配,增加 hash 分割槽可以重新分配資料 建立create table table name empno number,ename varchar 20 partition by hash empno partition p1,partition p2 檢視分割槽結構 sele...