exchange partition 實驗
本實驗的主要有兩個目的:
1. 測試分割槽交換的命令
2. 模擬在交換分割槽的時候出現ORA-14099的錯誤,利用insert來建立分割槽
--首先建立兩張表結構相同的分割槽表T1,T2,再建立一張中間表T1_MIDDLE
SQL> create table t1 (id int,name varchar2(10),hire_date date)
2 partition by range(hire_date) interval(NUMTODSINTERVAL(7,'DAY'))
3 (partition p1 values less than (to_date('05-Jan-2015','dd-mon-yyyy')));
Table created.
SQL>
SQL> create table t2 (id int,name varchar2(10),hire_date date)
2 partition by range(hire_date) interval(NUMTODSINTERVAL(7,'DAY'))
3 (partition p1 values less than (to_date('05-Jan-2015','dd-mon-yyyy')));
Table created.
SQL>
SQL> create table t1_middle (id int,name varchar2(10),hire_date date);
Table created.
--目前T1表只有一個預設分割槽P1
SQL> select partition_name from dba_tab_partitions where table_name='T1';
PARTITION_NAME
------------------------------
P1
--往T1表插入資料,構建資料
SQL> insert into t1 values(1,'a','31-JUL-15');
1 row created.
SQL> insert into t1 values(2,'b','30-JUL-15');
1 row created.
SQL> insert into t1 values(3,'c','29-JUL-15');
1 row created.
SQL> insert into t1 values(4,'d','14-JUL-15');
1 row created.
SQL> insert into t1 values(5,'e','4-AUG-15');
1 row created.
SQL> insert into t1 values(6,'F','6-AUG-15');
1 row created.
SQL> insert into t1 values(7,'F','7-AUG-15');
1 row created.
SQL> insert into t1 values(8,'G','5-AUG-15');
1 row created.
SQL> commit;
Commit complete.
--此時查詢一下表T1有哪些分割槽,由於插入資料,新增了幾個分割槽
SQL> select partition_name from dba_tab_partitions where table_name='T1';
PARTITION_NAME
------------------------------
P1
SYS_P50
SYS_P49
SYS_P51
--查詢T1表每個分割槽的資料
SQL> select COUNT(1) from t1 partition (SYS_P49);
COUNT(1)
----------
3
SQL> select COUNT(1) from t1 partition (SYS_P50);
COUNT(1)
----------
1
SQL> select COUNT(1) from t1 partition (SYS_P51);
COUNT(1)
----------
4
SQL> SELECT COUNT(1) FROM T1_MIDDLE;
COUNT(1)
----------
0
SQL> SELECT COUNT(1) FROM T1;
COUNT(1)
----------
8
--接下來我們嘗試交換分割槽,將SYS_P51這個分割槽的資料交換到臨時表T1_MIDDLE中,交換後SYS_P51中的4條資料沒有了,而中間表T1_MIDDLE有了4條資料
SQL> alter table t1 exchange partition SYS_P51 WITH table t1_middle update global indexes;
Table altered.
SQL> SELECT COUNT(1) FROM T1;
COUNT(1)
----------
4
SQL> select COUNT(1) from t1 partition (SYS_P51);
COUNT(1)
----------
0
SQL> SELECT COUNT(1) FROM T1_MIDDLE;
COUNT(1)
----------
4
--我們看下T2表的分割槽情況
SQL> select partition_name from dba_tab_partitions where table_name='T2';
PARTITION_NAME
------------------------------
P1
SQL> select count(1) from t2;
COUNT(1)
----------
0
--我們嘗試把中間表T1_MIDDLE的資料交換到目標表T2中,在交換的過程中遇到了ORA-14099的錯誤,原因是沒有指定的分割槽
SQL> alter table t2 exchange partition p1 with table t1_middle update global indexes;
alter table t2 exchange partition p1 with table t1_middle update global indexes
*
ERROR at line 1:
ORA-14099: all rows in table do not qualify for specified partition
--我們可以利用insert 建立分割槽,然後馬上進行rollback
SQL> insert into t2 select * from t1_middle where rownum=1
2 ;
1 row created.
SQL> rollback;
Rollback complete.
--再查下分割槽表T2的分割槽,增加了一個SYS_P52的分割槽
SQL> select partition_name from dba_tab_partitions where table_name='T2';
PARTITION_NAME
------------------------------
P1
SYS_P52
--此時再進行分割槽交換,分割槽交換後,中間表T1_MIDDLE的資料沒有了,交換到了目標表T2中
SQL> alter table t2 exchange partition SYS_P52 with table t1_middle update global indexes;
Table altered.
SQL> SELECT COUNT(1) FROM T1_MIDDLE;
COUNT(1)
----------
0
SQL> select count(1) from t2;
COUNT(1)
----------
4
SQL> select count(1) from t1;
COUNT(1)
----------
4
1. 測試分割槽交換的命令
2. 模擬在交換分割槽的時候出現ORA-14099的錯誤,利用insert來建立分割槽
--首先建立兩張表結構相同的分割槽表T1,T2,再建立一張中間表T1_MIDDLE
SQL> create table t1 (id int,name varchar2(10),hire_date date)
2 partition by range(hire_date) interval(NUMTODSINTERVAL(7,'DAY'))
3 (partition p1 values less than (to_date('05-Jan-2015','dd-mon-yyyy')));
Table created.
SQL>
SQL> create table t2 (id int,name varchar2(10),hire_date date)
2 partition by range(hire_date) interval(NUMTODSINTERVAL(7,'DAY'))
3 (partition p1 values less than (to_date('05-Jan-2015','dd-mon-yyyy')));
Table created.
SQL>
SQL> create table t1_middle (id int,name varchar2(10),hire_date date);
Table created.
--目前T1表只有一個預設分割槽P1
SQL> select partition_name from dba_tab_partitions where table_name='T1';
PARTITION_NAME
------------------------------
P1
--往T1表插入資料,構建資料
SQL> insert into t1 values(1,'a','31-JUL-15');
1 row created.
SQL> insert into t1 values(2,'b','30-JUL-15');
1 row created.
SQL> insert into t1 values(3,'c','29-JUL-15');
1 row created.
SQL> insert into t1 values(4,'d','14-JUL-15');
1 row created.
SQL> insert into t1 values(5,'e','4-AUG-15');
1 row created.
SQL> insert into t1 values(6,'F','6-AUG-15');
1 row created.
SQL> insert into t1 values(7,'F','7-AUG-15');
1 row created.
SQL> insert into t1 values(8,'G','5-AUG-15');
1 row created.
SQL> commit;
Commit complete.
--此時查詢一下表T1有哪些分割槽,由於插入資料,新增了幾個分割槽
SQL> select partition_name from dba_tab_partitions where table_name='T1';
PARTITION_NAME
------------------------------
P1
SYS_P50
SYS_P49
SYS_P51
--查詢T1表每個分割槽的資料
SQL> select COUNT(1) from t1 partition (SYS_P49);
COUNT(1)
----------
3
SQL> select COUNT(1) from t1 partition (SYS_P50);
COUNT(1)
----------
1
SQL> select COUNT(1) from t1 partition (SYS_P51);
COUNT(1)
----------
4
SQL> SELECT COUNT(1) FROM T1_MIDDLE;
COUNT(1)
----------
0
SQL> SELECT COUNT(1) FROM T1;
COUNT(1)
----------
8
--接下來我們嘗試交換分割槽,將SYS_P51這個分割槽的資料交換到臨時表T1_MIDDLE中,交換後SYS_P51中的4條資料沒有了,而中間表T1_MIDDLE有了4條資料
SQL> alter table t1 exchange partition SYS_P51 WITH table t1_middle update global indexes;
Table altered.
SQL> SELECT COUNT(1) FROM T1;
COUNT(1)
----------
4
SQL> select COUNT(1) from t1 partition (SYS_P51);
COUNT(1)
----------
0
SQL> SELECT COUNT(1) FROM T1_MIDDLE;
COUNT(1)
----------
4
--我們看下T2表的分割槽情況
SQL> select partition_name from dba_tab_partitions where table_name='T2';
PARTITION_NAME
------------------------------
P1
SQL> select count(1) from t2;
COUNT(1)
----------
0
--我們嘗試把中間表T1_MIDDLE的資料交換到目標表T2中,在交換的過程中遇到了ORA-14099的錯誤,原因是沒有指定的分割槽
SQL> alter table t2 exchange partition p1 with table t1_middle update global indexes;
alter table t2 exchange partition p1 with table t1_middle update global indexes
*
ERROR at line 1:
ORA-14099: all rows in table do not qualify for specified partition
--我們可以利用insert 建立分割槽,然後馬上進行rollback
SQL> insert into t2 select * from t1_middle where rownum=1
2 ;
1 row created.
SQL> rollback;
Rollback complete.
--再查下分割槽表T2的分割槽,增加了一個SYS_P52的分割槽
SQL> select partition_name from dba_tab_partitions where table_name='T2';
PARTITION_NAME
------------------------------
P1
SYS_P52
--此時再進行分割槽交換,分割槽交換後,中間表T1_MIDDLE的資料沒有了,交換到了目標表T2中
SQL> alter table t2 exchange partition SYS_P52 with table t1_middle update global indexes;
Table altered.
SQL> SELECT COUNT(1) FROM T1_MIDDLE;
COUNT(1)
----------
0
SQL> select count(1) from t2;
COUNT(1)
----------
4
SQL> select count(1) from t1;
COUNT(1)
----------
4
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26084062/viewspace-1764924/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Exchange Partition的實驗例子
- exchange partition
- exchange partition(轉)
- Pruning、Reference Partition、Exchange Partition
- exchange partition原理探究
- exchange partition 的用法
- [Oracle] Partition table exchange Heap tableOracle
- exchange partition的一些測試
- 巧妙使用exchange partition的一個案例
- 轉摘:EXCHANGE PARTITION those pesky columns
- Exchange partition分割槽結構的“乾坤挪移”
- 【實驗】【PARTITION】RANGE分割槽建立
- 分割槽表UNUSED列後的EXCHANGE PARTITION操作
- Oracle drop,truncate partition 索引失效 實驗Oracle索引
- 實驗】【PARTITION】RANGE分割槽建立【轉】
- 使用exchange partition來交換不同schema之間的表
- 記次10g exchange partition很慢的問題
- exchange partition 交換的問題ORA-14130:
- 【實驗】【PARTITION】RANGE分割槽表截斷表分割槽(Truncate Partition)
- 【實驗】【PARTITION】RANGE分割槽表移動表分割槽(Move Partition)
- 【實驗】【PARTITION】RANGE分割槽表重新命名錶分割槽(Rename Partition)
- Oracle Interval Partition 自動分割槽表-實驗Oracle
- 【實驗】【PARTITION】RANGE分割槽表合併分割槽
- 【實驗】【PARTITION】RANGE分割槽表增加分割槽
- 【實驗】【PARTITION】exp匯出分割槽表資料
- 【實驗】【PARTITION】RANGE分割槽表刪除分割槽
- Oracle12c分割槽新特性之TRUNCATEPARTITION和EXCHANGE PARTITION級聯功能Oracle
- partition table and partition indexIndex
- PARTITION partition01
- PARTITION partition02
- PARTITION partition04
- partition timestamp(0) not use partition
- Exchange域名重寫,實現SMTP地址共享
- 【實驗】【PARTITION】交換分割槽時分割槽表有主鍵目標表亦需有主鍵
- 【實驗】【PARTITION】RANGE分割槽表未指定maxvalue分割槽將無法插入相關資料
- PARTITION SPILT
- hive partitionHive
- over (partition by)