【實驗】【PARTITION】RANGE分區表增加分區


1.增加分區的SQL語法
alter table table_name add partition ...

2.創建一個分區表
sec@ora10g> drop table t_partition_range purge;

Table dropped.

sec@ora10g> create table t_partition_range (id number,name varchar2(50))
2 partition by range(id)(
3 partition t_range_p1 values less than (10) tablespace tbs_part01,
4 partition t_range_p2 values less than (20) tablespace tbs_part02,
5 partition t_range_p3 values less than (30) tablespace tbs_part03
6 );

Table created.

sec@ora10g> col TABLE_NAME for a20
sec@ora10g> col partition_name for a20
sec@ora10g> col HIGH_VALUE for a10
sec@ora10g> col TABLESPACE_NAME for a15
sec@ora10g> select table_name,partition_name,high_value,tablespace_name from user_tab_partitions where table_name='T_PARTITION_RANGE' order by partition_position;

TABLE_NAME           PARTITION_NAME       HIGH_VALUE TABLESPACE_NAME
-------------------- -------------------- ---------- ---------------
T_PARTITION_RANGE    T_RANGE_P1           10         TBS_PART01
T_PARTITION_RANGE    T_RANGE_P2           20         TBS_PART02
T_PARTITION_RANGE    T_RANGE_P3           30         TBS_PART03

3.添加一個分區t_range_p4
sec@ora10g> alter table t_partition_range add partition t_range_p4 values less than(40) tablespace tbs_part04;

Table altered.

sec@ora10g> select table_name,partition_name,high_value,tablespace_name from user_tab_partitions where table_name='T_PARTITION_RANGE' order by partition_position;

TABLE_NAME           PARTITION_NAME       HIGH_VALUE TABLESPACE_NAME
-------------------- -------------------- ---------- ---------------
T_PARTITION_RANGE    T_RANGE_P1           10         TBS_PART01
T_PARTITION_RANGE    T_RANGE_P2           20         TBS_PART02
T_PARTITION_RANGE    T_RANGE_P3           30         TBS_PART03
T_PARTITION_RANGE    T_RANGE_P4           40         TBS_PART04

從這個實驗結果可以看到t_range_p4分區已經創建成功

4.命題:如果在創建RANGE分區表的時候指定了maxvalue,不可以添加分區(需要使用split方法來處理)

5.實驗證明之

6.創建帶有maxvalue的分區表
sec@ora10g> drop table t_partition_range purge;

Table dropped.

sec@ora10g> create table t_partition_range (id number,name varchar2(50))
2 partition by range(id)(
3 partition t_range_p1   values less than (10) tablespace tbs_part01,
4 partition t_range_p2   values less than (20) tablespace tbs_part02,
5 partition t_range_p3   values less than (30) tablespace tbs_part03,
6 partition t_range_pmax values less than (maxvalue) tablespace tbs_part04);

Table created.

7.此時添加分區時會報如下的錯誤
sec@ora10g> alter table t_partition_range add partition t_range_p4 values less than(40) tablespace tbs_part04;
alter table t_partition_range add partition t_range_p4 values less than(40) tablespace tbs_part04
                                            *
ERROR at line 1:
ORA-14074: partition bound must collate higher than that of the last partition

難道針對這樣的分區表就不能修改添加分區了么?對於強大的oracle來說那是不可能的,處理方法是使用split的方法來處理之。

8.展示使用split完成上面沒有完成的分區任務
sec@ora10g> alter table t_partition_range split partition t_range_pmax at (40) into (partition tbs_part05, partition t_range_pmax);

Table altered.

sec@ora10g> select table_name,partition_name,high_value,tablespace_name from user_tab_partitions where table_name='T_PARTITION_RANGE' order by partition_position;


TABLE_NAME           PARTITION_NAME       HIGH_VALUE TABLESPACE_NAME
-------------------- -------------------- ---------- ----------------
T_PARTITION_RANGE    T_RANGE_P1           10         TBS_PART01
T_PARTITION_RANGE    T_RANGE_P2           20         TBS_PART02
T_PARTITION_RANGE    T_RANGE_P3           30         TBS_PART03
T_PARTITION_RANGE    T_RANGE_P4           40         TBS_PART05
T_PARTITION_RANGE    T_RANGE_PMAX         MAXVALUE   TBS_PART04

OK,搞定。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM