一
創建一個列表分區表
create table t
partition by list(city)
(
partition p
partition p
partition p
partition p_others values (default)
);
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
create or replace procedure proc
as
begin
for i in
loop
execute immediate
end loop;
end;
/
exec proc
SQL> SET linesize
SQL> select TABLE_NAME
TABLE_NAME TABLE_OWNER PARTITION_NAME SUBPARTITION_COUNT
T
T
T
T
實驗一(SPLIT 分區)
alter table t
(partition p
SQL> select TABLE_NAME
TABLE_NAME TABLE_OWNER PARTITION_NAME SUBPARTITION_COUNT
T
T
T
T
T
實驗二(merge 分區)
alter table t
SQL> select TABLE_NAME
TABLE_NAME TABLE_OWNER PARTITION_NAME SUBPARTITION_COUNT
T
T
T
T
實驗三
alter table t
(partition p
SQL> select TABLE_NAME
TABLE_NAME TABLE_OWNER PARTITION_NAME SUBPARTITION_COUNT
T
T
T
T
T
實驗四
alter table t
SQL> select TABLE_NAME
TABLE_NAME TABLE_OWNER PARTITION_NAME SUBPARTITION_COUNT
T
T
T
T
實驗五( 向分區某個分區裡增加個分區列值)
SQL> alter table t
Table altered
二
實驗六(創建索引分區)
create index idx_t
global partition by range(id)
(
partition p
partition p
);
drop index idx_
create index idx_t
global partition by hash(id)
partitions
create table tt
partition by range(createdate)
subpartition by hash(id) subpartitions
(
partition p
partition p
);
create table tt
partition by range(name)
(
partition p
partition p
);
create index idx_tt
drop indexe idx_tt
create index idx_tt
global partition by range(id)
(
partition p
partition p
);
SQL> SET LINESIZE
SQL> select INDEX_OWNER
INDEX_OWNER INDEX_NAME PARTITION_NAME
HR IDX_TT
HR IDX_TT
alter index idx_tt
(partition p
SQL> select INDEX_OWNER
INDEX_OWNER INDEX_NAME PARTITION_NAME
HR IDX_TT
HR IDX_TT
HR IDX_TT
三
Exchange partition提供了一種方式
由於其號稱是采用了更改數據字典的方式
也可以從非分區表遷移至分區表
其語法
注意
則
a
b
c
d
注意
一旦附加了without validation子句
創建一個交換分區的普通heap表
SQL> create table exchange_t
Table created
SQL> select distinct city from t
CITY
TJ
BJ
HB
查看下P
SQL> select count(*) from t
COUNT(*)
下面是分區表和普通HEAP表交換
alter table t
exchange partition p
with table exchange_t
including indexes
without validation;
驗證下數據
SQL> select count(*) from exchange_t
COUNT(*)
SQL> select distinct city from exchange_t
CITY
TJ
BJ
HB
四
創建一個分區表
create table ware(wareyear varchar
partition by range (wareyear)
(
partition p_
partition p_
partition p_max values less than(maxvalue)
);
創建索引
create index idx_ware_id on ware(id)
global partition by range(id)
(
partition p_id_
partition p_id_max values less than(maxvalue)
);
create index idx_ware_wareyear on ware(wareyear) local;
插入測試數據
insert into ware select
insert into ware select
commit;
年終
create table ware_
create index idx_ware_
insert into ware_
commit;
alter table ware split partition p_max
at (
將p_
alter table ware exchange partition p_
with table ware_
including indexes
without validation;
create table ware_
create index idx_ware_
alter table ware exchange partition p_
with table ware_
including indexes
without validation;
刪除p_
alter table ware drop partition p_
導出做歸檔
[oracle@even admin]$ exp hr/hr@test file=/home/oracle/ware_
Export: Release
Copyright (c)
Connected to: Oracle Database
With the Partitioning
Export done in US
server uses AL
About to export specified tables via Conventional Path
Export terminated successfully without warnings
然後刪除表
drop table ware_
五
對於分區索引
Alter index idx_name rebuild partition index_partition_name [online nologging]
Alter Index IndexName Rebuild Partition P_Name;
有子分區的本地索引
Alter Index Index_Name Rebuild subPartition P_Sub_Name;
腳本
Select
Select
Select
add parttion
Alter Table TestTab
exec dbms_stats
tuncate and drop partition
truncate和drop可對有子分區的分區進行
ALTER TABLE TEST truncate Partition P_
ALTER TABLE TEST Drop Partition P_
它們會導致globl index的某些分區不可用
ALTER TABLE TEST truncate Partition P_
ALTER TABLE TEST truncate Partition P_
ALTER TABLE TEST Drop Partition P_
ALTER TABLE TEST Drop Partition P_
move partition
有子分區的分區不能move
Alter Table TEST Move Partition P_
由於rowid變了
Alter Table TEST Move subPartition P_
Alter Table TEST Move subPartition P_
split partion
語法
alter table <table_name>
split partition <partition_name> at (<value>)
into (partition <partition_name>
[update [global] indexes];
alter table t
合並range分區
ALTER TABLE Test_Tab
Merge Partitions P_
[Update [global] Indexes];
可以通過下面的視圖獲取分區的信息
dba_segments
dba_part_key_columns
dba_tables
dba_tab_partitions
dba_indexes
dba_ind_partitions
From:http://tw.wingwit.com/Article/program/Oracle/201311/19037.html