Oracle - 使用列表范围分区的EXCHANGE PARTITION错误

时间:2016-03-02 13:46:29

标签: oracle database-partitioning

我正在尝试在以下示例模式中使用EXCHANGE PARTITION:

CREATE TABLE TEMP_TABLE_00(
    CONTACT_ID NUMBER,
    SECONDARY_CONTACT_FLAG NUMBER, 
    SOURCE_SYSTEM VARCHAR2(10 CHAR), 
    START_DATE DATE, 
    ACTIVE NUMBER,
    SECONDARY_CONTACT_FLAGS NUMBER GENERATED ALWAYS AS (ACTIVE || SECONDARY_CONTACT_FLAG) VIRTUAL,
    CONSTRAINT pk_temp_table_00 PRIMARY KEY (CONTACT_ID))  

PARTITION BY LIST (SECONDARY_CONTACT_FLAGS) 
SUBPARTITION BY RANGE (START_DATE)
( PARTITION p_ac_00 VALUES ('00') 
  ( SUBPARTITION sp_ac_00_before_2014  VALUES LESS THAN (TO_DATE ('01.01.2014', 'DD.MM.YYYY')),
    SUBPARTITION sp_ac_00_201401       VALUES LESS THAN (TO_DATE ('01.02.2014', 'DD.MM.YYYY'))
  )    
)
ENABLE ROW MOVEMENT;

create table TARGET_TABLE(
    CONTACT_ID NUMBER, 
    SECONDARY_CONTACT_FLAG NUMBER, 
    SOURCE_SYSTEM VARCHAR2(10 CHAR), 
    START_DATE DATE, 
    ACTIVE NUMBER,
    SECONDARY_CONTACT_FLAGS NUMBER GENERATED ALWAYS AS (ACTIVE || SECONDARY_CONTACT_FLAG) VIRTUAL,
    CONSTRAINT pk_target_table PRIMARY KEY (CONTACT_ID))  
PARTITION BY LIST (secondary_contact_flags) 
SUBPARTITION BY RANGE (START_DATE)
( PARTITION p_ac_00 VALUES ('00') 
  ( SUBPARTITION sp_ac_00_before_2014  VALUES LESS THAN (TO_DATE ('01.01.2014', 'DD.MM.YYYY')),
    SUBPARTITION sp_ac_00_201401       VALUES LESS THAN (TO_DATE ('01.02.2014', 'DD.MM.YYYY'))
   ),
  PARTITION p_ac_10 VALUES ('10') 
  ( SUBPARTITION sp_ac_10_before_2014  VALUES LESS THAN (TO_DATE ('01.01.2014', 'DD.MM.YYYY')),
    SUBPARTITION sp_ac_10_201401       VALUES LESS THAN (TO_DATE ('01.02.2014', 'DD.MM.YYYY'))

  ),
  PARTITION p_ac_01 VALUES ('01') 
  ( SUBPARTITION sp_ac_01_before_2014  VALUES LESS THAN (TO_DATE ('01.01.2014', 'DD.MM.YYYY')),
    SUBPARTITION sp_ac_01_201401       VALUES LESS THAN (TO_DATE ('01.02.2014', 'DD.MM.YYYY'))

  ),
  PARTITION p_ac_11 VALUES ('11') 
  ( SUBPARTITION sp_ac_11_before_2014  VALUES LESS THAN (TO_DATE ('01.01.2014', 'DD.MM.YYYY')),
    SUBPARTITION sp_ac_11_201401       VALUES LESS THAN (TO_DATE ('01.02.2014', 'DD.MM.YYYY'))

  )
)
ENABLE ROW MOVEMENT;

INSERT INTO DM_KSCTSC.TEMP_TABLE_00 (CONTACT_ID, SECONDARY_CONTACT_FLAG, SOURCE_SYSTEM, START_DATE, ACTIVE) VALUES (1, 0, 'ABC', TO_DATE('20140101', 'YYYYMMDD'), 0);
commit;

尝试交换分区时:

alter table target_table exchange partition p_ac_00 with table TEMP_TABLE_00 without validation;

即使分区的结构相同,Oracle也会返回

  

ORA-14292:表的分区类型必须与子分区类型匹配   复合分区

是否存在另一种解决方案,而不是单独交换每个子分区?

1 个答案:

答案 0 :(得分:2)

为了能够在分区表(PT)和非分区表(TMP)之间交换分区,TMP表必须具有与PT分区相同的结构

即。如果PT被分区,则TMP未被分区。

如果PT是复合分区,则TMP的分区方式与PT的子分区相同。

在你的情况下是TMP表中的问题(TEMP_TABLE_00),它必须 (与TARGET_TABLE的子分区相同)

CREATE TABLE TEMP_TABLE_00(
    CONTACT_ID NUMBER,
    SECONDARY_CONTACT_FLAG NUMBER, 
    SOURCE_SYSTEM VARCHAR2(10 CHAR), 
    START_DATE DATE, 
    ACTIVE NUMBER,
    SECONDARY_CONTACT_FLAGS NUMBER GENERATED ALWAYS AS (ACTIVE || SECONDARY_CONTACT_FLAG) VIRTUAL,
    CONSTRAINT pk_temp_table_00 PRIMARY KEY (CONTACT_ID))  

PARTITION BY  RANGE (START_DATE)

  (  PARTITION sp_ac_00_before_2014  VALUES LESS THAN (TO_DATE ('01.01.2014', 'DD.MM.YYYY')),
     PARTITION sp_ac_00_201401       VALUES LESS THAN (TO_DATE ('01.02.2014', 'DD.MM.YYYY'))
  )    

ENABLE ROW MOVEMENT;

在此设置中,交换分区可以正常工作。