1按需建立分割槽,可以自動擴充套件分割槽
create table f_sales(sales_amt number,d_date date)partition by range (d_date) interval(numtoyminterval(1,'year')) (partition p1 values less than(to_date('01-jan-2010','dd-mon-yyyy')));
2通過partition by reference子句來指定子表與父表同樣的方式進行分割槽
create table orders( order_id number,order_date date,constraint order_pk primary key(order_id))partition by range(order_date)(partition p10 values less than(to_date('01-jan-2010','dd-mon-yyyy')));
create tale order_items(line_id number,order_id number not null,constraint order_items_pk primary key(line_id,order_id),constraint order_items_fk1 foreign key(order_id) references orders) partition by reference(order_items_fk1);
3基於虛擬列的分割槽
create table emp(emp_id numbser,salary number,comm_pct number,commission generated always as (salary*comm_pct))partition by range(commission)(
partition p1 values less than (1000),partition p2 values less than(2000),partition p3 valeus less than (maxvalue));
4自定義插入到哪個分割槽,系統分割槽
create table test (id int ,name varchar2(100)) partition by system(partition p1,partition p2,partition p3);
insert into test partition(p1) values(1,'test'):
5更改分割槽鍵,讓記錄能更換分割槽,而不是報錯
alter table test enable row movement;
6交換分割槽,把乙個表變成乙個分割槽,或將乙個分割槽變成乙個表(實驗)
create table f_sales(sales_amt number, d_date_id number)
partition by range(d_date_id)
(partition p_2007 values less than(20080101),
partition p_2008 values less than (20090101),
partition p_2009 values less than (20100101));
create bitmap index d_date_id_fk1 on f_sales(d_date_id) local;
alter table f_sales add partition p_2010 values less than(20110101);
create table workpart(sales_amt number,d_date_id number);
insert into workpart values(100,20100101);
insert into workpart values(200,20100102);
create bitmap index d_date_id_fk2 on workpart(d_date_id);
alter table f_sales exchange partition p_2010 with table workpart including indexes without validation;
select * from workpart;
select * from f_sales partition(p_2010);
select index_name,partition_name,status from user_ind_partitions where index_name like 'd_date%';
7拆分分割槽
alter table f_sales split partition p_2010 at (20100601) into (partition p2010_a,partition p2010) update indexes;
select * from user_part_tables a where a.table_name='f_sales';
select * from user_tab_partitions a where a.table_name='f_sales';
insert into f_sales values(300,20100401);
insert into f_sales values(400,20101001);
select * from f_sales partition(p2010_a);
select * from f_sales partition(p2010);
上面的拆分的範圍分割槽
下面的是拆分的列表分割槽
alter table f_sales split partition reg_mid values('ia','ks','mi','mn') into (partition reg_mid_a,partition reg_mid_b);
8合併分割槽
alter table f_sales merge partitions p2010_a,p2010 into partition pp2010;
select * from user_tab_partitions a where a.table_name='f_sales';
在合併的時候分割槽的名稱是可以指定的
select index_name,partition_name,status from user_ind_partitions where index_name like 'd_date%';
1d_date_id_fk1pp2010unusable
2d_date_id_fk1p_2007usable
3d_date_id_fk1p_2008usable
4d_date_id_fk1p_2009usable
合併後的分割槽,本地索引是失效了的,使用下面的語句重建本地索引
alter table f_sales modify partition pp2010 rebuild unusable local indexes;
9刪除分割槽
alter table f_sales drop partition pp2010;
10刪除乙個分割槽中的記錄
alter table f_sales truncate partition p_2008;
delete from f_sales partition(p_2008);
11建立本地索引,本地索引分割槽索引的分割槽與表的分割槽不在一起
create index i_f_sales on f_sales(d_date_id) local(partition p2009 tablespace idx1,partition p2010 tablespace idx2);
本地分割槽索引分有字首的本地分割槽索引和無字首的區域性索引,有字首的區域性分割槽索引就是索引最左側的列是分割槽列,無字首索引就是最左側的列不是分割槽列
可以檢視
select index_name,table_name,alignment,locality from user_part_indexs;檢視索引是否是字首索引
12建立全域性索引
我們在乙個不是分割槽鍵的字段查詢分割槽表,想要在這個欄位上建立乙個索引來提高效能,建立全域性索引,全域性索引有雜湊分割槽或範圍全域性索引,
create index f_sales on f_sales(sales_id) global partition by range(sales_id) (partition pg1 values less than (100),partition pg2 values less than (200),partition pg3 values less than (maxvalue));
create index f_sales_idx on f_sales(count) global partition by hash(count) partitions 3;
Oracle 11g筆記 分割槽表
一 分割槽表 分割槽技術,oracle允許把乙個大表分成幾部分,每部分叫乙個分割槽,然後把每個部分放在不同的物理磁碟,以提高整個資料庫的效能。每個分割槽還可以再分成幾份,這樣產生的分割槽叫子分割槽 subpartition 分割槽表邏輯上還是乙個整體。1 優點 1 分割槽技術使資料庫的可管理性變得更...
oracle 11g 按時間建分割槽表
假如已建立的表不能再建立分割槽,只有重新建分割槽表,然後將資料匯入表中,再將表名改為原表名 1.我的原表名為monitor data,現在建臨時分割槽表 create table gps monitor data tmp data id char 36 byte not null,equip id ...
oracle11g分割槽表按時間自動建立
首先來介紹下numtodsinterval和numtoyminterval兩個函式。numtoyminterval和numtoyminterval是日期轉換函式,作用 可以將數字轉換成相應的日期單位時間 語法 numtoyminterval n char expr char expr 日期描述,可以...