【实验】【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,搞定。

分类:  OralceRac

本文转自einyboy博客园博客,原文链接:http://www.cnblogs.com/einyboy/archive/2012/07/25/2608766.html
目录
相关文章
|
2月前
|
人工智能 自然语言处理 监控
分区Partition介绍及应用
本文详细介绍分区Partition的概念及使用场景,具体如何使用。
|
5月前
Hologres的`dynamicPartition`参数是用来实现动态分区的
Hologres的`dynamicPartition`参数是用来实现动态分区的
46 0
|
SQL HIVE
hive插入分区报错SemanticException Partition spec contains non-partition columns
hive插入分区报错SemanticException Partition spec contains non-partition columns
|
分布式计算 Spark
【spark系列11】spark 的动态分区裁剪下(Dynamic partition pruning)-物理计划
【spark系列11】spark 的动态分区裁剪下(Dynamic partition pruning)-物理计划
7650 0
|
分布式计算 Spark
【spark系列9】spark 的动态分区裁剪上(Dynamic partition pruning)-逻辑计划
【spark系列9】spark 的动态分区裁剪上(Dynamic partition pruning)-逻辑计划
288 0
|
消息中间件 Kafka
Kafka分区分配计算(分区器Partitions)
KafkaProducer在调用send方法发送消息至broker的过程中,首先是经过拦截器Inteceptors处理,然后是经过序列化Serializer处理,之后就到了Partitions阶段,即分区分配计算阶段。
3721 0