如何在Oracle 12C中添加多个分区 (Doc ID 1482456.1)

Posted Oracle&PostgreSQL

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Oracle 12C中添加多个分区 (Doc ID 1482456.1)相关的知识,希望对你有一定的参考价值。

How to Add Multiple Partitions in Oracle 12C (Doc ID 1482456.1)

APPLIES TO:

Oracle Database - Enterprise Edition - Version 12.1.0.1 and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Oracle Database Cloud Exadata Service - Version N/A and later
Information in this document applies to any platform.
Oracle 12C

GOAL

 To demonstrate new feature in 12c, adding multiple table partitions in a single command  为了演示12c中的新功能,请在单个命令中添加多个表分区

SOLUTION

NOTE: In the images and/or the document content below, the user information and data used represents fictitious data from the Oracle sample schema(s) or Public Documentation delivered with an Oracle database product.  Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner. 

You can add multiple new partitions with the ADD PARTITION clause of the ALTER TABLE statement. When adding multiple partitions, local and global index operations are the same as when adding a single partition. Note that both ADD PARTITION and ADD PARTITIONS are synonymous.
您可以使用 ALTER TABLE 语句的 ADD PARTITION 子句添加多个新分区。 添加多个分区时,本地索引和全局索引操作与添加单个分区时相同。 请注意,ADD PARTITION 和 ADD PARTITIONS 都是同义词。

RANGE PARTITIONS  范围分区

You can add multiple range partitions that are listed in ascending order of their upper bound values to the high end (after the last existing partition) of a range-partitioned or composite range-partitioned table, provided the MAXVALUE partition is not defined.
您可以将以上限值的升序排列的多个范围分区添加到范围分区表或组合范围分区表的高端(在最后一个现有分区之后),前提是未定义MAXVALUE分区。

CREATE TABLE sales
(prod_id NUMBER(6),
cust_id NUMBER,
time_id DATE,
channel_id CHAR(1),
promo_id NUMBER(6),
quantity_sold NUMBER(3),
amount_sold NUMBER(10,2))
partition by range(time_id)
(partition sales_q1_2006 values less than (TO_DATE(‘01-APR-2006‘,‘dd-MON-yyyy‘)),
partition sales_q2_2006 values less than (TO_DATE(‘01-JUL-2006‘,‘dd-MON-yyyy‘)),
partition sales_q3_2006 values less than (TO_DATE(‘01-OCT-2006‘,‘dd-MON-yyyy‘)),
partition sales_q4_2006 values less than (TO_DATE(‘01-JAN-2007‘,‘dd-MON-yyyy‘)));

The above example creates a sales table with four partitions, one for each quarter of 2006. 上面的示例创建了一个具有四个分区的sales表,
Each partition is given a name: sales_q1_2006, sales_q2_2006, sales_q3_2006, and sales_q4_2006.  每个分区用于2006年的每个季度。每个分区都有一个名称:sales_q1_2006,sales_q2_2006,sales_q3_2006和sales_q4_2006。
The time_id column is the partitioning column, while its value represents the partitioning key of a specific row.  time_id列是分区列,而其值表示特定行的分区键。
The VALUES LESS THAN clause determines the partition bound: Rows with partitioning key values that compare less than the ordered list of values specified by the clause are stored in the partition. 
VALUES LESS THAN子句确定分区的边界:分区键值的行比该子句指定的值的有序列表小的行存储在分区中。
For example, a row with time_id=17-MAR-2006 would be stored in partition sales_q1_2006.  例如,time_id = 17-MAR-2006的行将存储在分区sales_q1_2006中。

You can add multiple partitions using a single statement by specifying the individual partitions. 您可以通过指定单个分区来使用单个语句添加多个分区
For example, in the below example, you add multiple partitions to the Range-partitioned sales table created earlier named sales_q1_2007, sales_q2_2007, sales_q3_2007 and sales_q4_2007.
例如,在下面的示例中,您将多个分区添加到先前创建的名为sales_q1_2007,sales_q2_2007,sales_q3_2007和sales_q4_2007的范围分区销售表中。

ALTER TABLE sales ADD
  PARTITION sales_q1_2007 VALUES LESS THAN (TO_DATE(‘01-APR-2007‘,‘dd-MON-yyyy‘)),
  PARTITION sales_q2_2007 VALUES LESS THAN (TO_DATE(‘01-JUL-2007‘,‘dd-MON-yyyy‘)),
  PARTITION sales_q3_2007 VALUES LESS THAN (TO_DATE(‘01-OCT-2007‘,‘dd-MON-yyyy‘)),
  PARTITION sales_q4_2007 VALUES LESS THAN (TO_DATE(‘01-JAN-2008‘,‘dd-MON-yyyy‘));

LIST PARTITIONS  列表分区

You can add multiple list partitions to a table using new sets of partition values if the DEFAULT partition does not exist.  如果DEFAULT分区不存在,则可以使用新的分区值集将多个列表分区添加到一个表中。

CREATE TABLE sales_list
(salesman_name VARCHAR2(30),
sales_state   VARCHAR2(20))
PARTITION BY LIST(sales_state)
(
PARTITION sales_CA VALUES(‘California‘),
PARTITION sales_NY VALUES (‘New York‘),
PARTITION sales_NJ VALUES (‘New Jersey‘),
PARTITION sales_CT VALUES (‘Connecticut‘),
PARTITION sales_PA VALUES (‘Pennsylvania‘),
PARTITION sales_IL VALUES(‘Illinois‘));


ALTER TABLE sales_list add
PARTITION sales_NE VALUES (‘Nebraska‘),
PARTITION sales_AZ VALUES (‘Arizona‘),
PARTITION sales_MD VALUES (‘Maryland‘);

SYSTEM PARTITIONS  系统分区

The BEFORE clause can be used to add multiple new system partitions in relation to only one existing partition. If the clause is specified at the end of the SQL statement, then all the new partitions are added before the partition specified in the clause. Otherwise, the new partitions are added after the existing partitions.  BEFORE子句可用于仅相对于一个现有分区添加多个新系统分区。如果在SQL语句的末尾指定了子句,则所有新分区都将添加到该子句中指定的分区之前。否则,新分区将添加到现有分区之后。
For example, the following SQL statement adds three new partitions before the part_last partition for the system partitioned table:  例如,以下SQL语句在系统分区表的part_last分区之前添加了三个新分区

ALTER TABLE system_table1 ADD PARTITIONS 3 BEFORE part_last;

 

The following SQL statement adds multiple individual partitions using the BEFORE clause:  以下SQL语句使用BEFORE子句添加多个单独的分区

ALTER TABLE system_table2 ADD
   PARTITION p5,
   PARTITION p6,
   PARTITION p7
   BEFORE PARTITION pMax;

REFERENCES

NOTE:785462.1 - 11g New Features: System Partitioning

以上是关于如何在Oracle 12C中添加多个分区 (Doc ID 1482456.1)的主要内容,如果未能解决你的问题,请参考以下文章

12C新功能:在线移动分区 (Doc ID 1584032.1)

在 oracle sql 12c 中可以绕过分区吗?

Oracle 12c 多租户家族(12c 18c 19c)如何在 PDB 中添加 HR 模式

如何在 oracle 12c 中使用多个数据更新单个列

Oracle 12c 添加scott用户

Oracle动态创建时间分区,以及Oracle12c中快速创建自增列