在Oracle 11g2中交换子分区分区

时间:2018-01-17 07:45:12

标签: sql oracle partitioning

我有两个表,具有相同的分区和子分区,填充了一些虚拟数据:

CREATE TABLE TEST_TBL_1(col_1 number, col_2 number, col_3 number, col_4 number ,col_5 VARCHAR2(100))
  PARTITION BY RANGE (col_1, col_2, col_3)
  SUBPARTITION BY RANGE (col_4)
(
  PARTITION PDUMMY
    VALUES LESS THAN (-1, -1, -1)
    ( SUBPARTITION SPDUMMY VALUES LESS THAN (-1)),
  PARTITION P_1_1_1
    VALUES LESS THAN (1, 1, 1)
    ( SUBPARTITION SP_1_1_1_1000 VALUES LESS THAN (1000),
      SUBPARTITION SP_1_1_1_2000 VALUES LESS THAN (2000),
      SUBPARTITION SP_1_1_1_3000 VALUES LESS THAN (3000)),
  PARTITION P_2_2_2
    VALUES LESS THAN (2, 2, 2)
    ( SUBPARTITION SP_2_2_2_1000 VALUES LESS THAN (1000),
      SUBPARTITION SP_2_2_2_2000 VALUES LESS THAN (2000),
      SUBPARTITION SP_2_2_2_3000 VALUES LESS THAN (3000)));

CREATE TABLE TEST_TBL_2(col_1 number, col_2 number, col_3 number, col_4 number ,col_5 VARCHAR2(100))
  PARTITION BY RANGE (col_1, col_2, col_3)
  SUBPARTITION BY RANGE (col_4)
(
  PARTITION PDUMMY
    VALUES LESS THAN (-1, -1, -1)
    ( SUBPARTITION SPDUMMY VALUES LESS THAN (-1)),
  PARTITION P_1_1_1
    VALUES LESS THAN (1, 1, 1)
    ( SUBPARTITION SP_1_1_1_1000 VALUES LESS THAN (1000),
      SUBPARTITION SP_1_1_1_2000 VALUES LESS THAN (2000),
      SUBPARTITION SP_1_1_1_3000 VALUES LESS THAN (3000)),
  PARTITION P_2_2_2
    VALUES LESS THAN (2, 2, 2)
    ( SUBPARTITION SP_2_2_2_1000 VALUES LESS THAN (1000),
      SUBPARTITION SP_2_2_2_2000 VALUES LESS THAN (2000),
      SUBPARTITION SP_2_2_2_3000 VALUES LESS THAN (3000)));


INSERT INTO TEST_TBL_1(col_1, col_2, col_3, col_4, col_5) values (1,1,0,500,  'TABLE 1: Partition P_1_1_1 subpartition SP_1_1_1_1000');
INSERT INTO TEST_TBL_1(col_1, col_2, col_3, col_4, col_5) values (1,1,0,1300, 'TABLE 1: Partition P_1_1_1 subpartition SP_1_1_1_2000');
INSERT INTO TEST_TBL_1(col_1, col_2, col_3, col_4, col_5) values (1,1,0,2700, 'TABLE 1: Partition P_1_1_1 subpartition SP_1_1_1_3000');
INSERT INTO TEST_TBL_1(col_1, col_2, col_3, col_4, col_5) values (1,1,0,2990, 'TABLE 1: Partition P_1_1_1 subpartition SP_1_1_1_3000');


INSERT INTO TEST_TBL_2(col_1, col_2, col_3, col_4, col_5) values (1,1,0,700,  'TABLE 2: Partition P_1_1_1 subpartition SP_1_1_1_1000');
INSERT INTO TEST_TBL_2(col_1, col_2, col_3, col_4, col_5) values (1,1,0,1500, 'TABLE 2: Partition P_1_1_1 subpartition SP_1_1_1_2000');
INSERT INTO TEST_TBL_2(col_1, col_2, col_3, col_4, col_5) values (1,1,0,2222, 'TABLE 2: Partition P_1_1_1 subpartition SP_1_1_1_3000');
INSERT INTO TEST_TBL_2(col_1, col_2, col_3, col_4, col_5) values (1,1,0,2323, 'TABLE 2: Partition P_1_1_1 subpartition SP_1_1_1_3000');

我的目标是将表1中的分区与表2中的相应分区交换,包括所有子分区数据。但是,如果我使用交换分区语法:

ALTER TABLE test_tbl_1
EXCHANGE PARTITION P_1_1_1
WITH TABLE test_tbl_2 ;

我最终会出错:

ORA-14293: Number of partitioning columns does not match number of subpartitioning columns

有没有办法在一个语句中交换这些表之间的分区?如果不是,请您指导我一步一步地完成这项工作的最有效方法吗?

感谢。

1 个答案:

答案 0 :(得分:1)

当您进行分区交换时,您正在交换:

  1. 具有非分区表的分区表 或
  2. 具有分区表的子分区表。
  3. 所以你需要在你的情况下使用两个步骤。您将拥有一个已分区的虚拟表。那你就

    使用虚拟交换table_1 partition_1 使用虚拟

    交换table_2 partition_1

    您将对所有必需的分区重复此操作。