Oracle分区表:数据未插入右侧分区

时间:2014-06-16 04:32:20

标签: database oracle11g

Halo数据库大师,来自印度尼西亚的问候

我目前正在努力将我的公司大表从非分区迁移到分区表。每次我尝试使用insert插入日志中的journal1 select *时,插入到journal1中的数据不会被分区。任何线索?

这里是非分区表作为数据源。

CREATE TABLE PRODBMDB.JOURNAL
(
  ID                  VARCHAR2(32 BYTE)         NOT NULL,
  GATEWAYID           VARCHAR2(128 BYTE)        DEFAULT NULL,
  WORKSTATIONID       VARCHAR2(128 BYTE),
  MANDATORID          NUMBER(19)                DEFAULT NULL,
  INSTITUTEID         NUMBER(19)                DEFAULT NULL,
  SUBSIDIARYID        NUMBER(19)                DEFAULT NULL,
  ACQUIRERID          NUMBER(19)                DEFAULT NULL,
  DATETIME            TIMESTAMP(6)              NOT NULL,
  SESSIONID           VARCHAR2(32 BYTE),
  AUTHORIZETSTAMP     TIMESTAMP(6),
  TRANSACTIONNUMBER   NUMBER(19)                NOT NULL,
  TRANSACTIONSTEPNR   NUMBER(19),
  CLIENTTRXNUM        NUMBER(19),
  HOSTTRXNUM          VARCHAR2(32 BYTE),
  METHOD              VARCHAR2(64 BYTE),
  ACTIONTYPE          NUMBER(38)                NOT NULL,
  ACTIONSUBTYPE       NUMBER(38),
  FRAUDRESULT         NUMBER(38),
  FRAUDSCORE          NUMBER(38),
  CUSTOMERID          VARCHAR2(32 BYTE),
  ROUTINGCODE         VARCHAR2(50 BYTE),
  ACCOUNTNUMBER       VARCHAR2(50 BYTE),
  CARDSEQUENCENUMBER  VARCHAR2(2 BYTE),
  AMOUNT              NUMBER(19),
  CURRENCYCODE        CHAR(3 BYTE),
  COMMANDSOURCE       VARCHAR2(128 BYTE),
  RESPONSECODE        NUMBER(38),
  EXTRESPONSECODE     NUMBER(38),
  CANCELREASON        NUMBER(38),
  DOCUMENTSTATE       NUMBER(38),
  ACCOUNTINGSTATE     NUMBER(38),
  CARDSTATE           NUMBER(38),
  HOSTSTATE           NUMBER(38),
  EISPH               NUMBER(38),
  PARTITION           NUMBER(38),
  CONFIDENTIALS       VARCHAR2(1024 BYTE),
  MEDVIEW             NUMBER(38),
  MINVIEW             NUMBER(38),
  LONGVIEW            NUMBER(38),
  DATA1               RAW(2000),
  DATA2               RAW(2000),
  DATA3               RAW(2000),
  DATA4               RAW(2000),
  DATA5               RAW(2000),
  DATA6               RAW(2000)
)
TABLESPACE USERSBIG
PCTUSED    0
PCTFREE    10
INITRANS   10
MAXTRANS   255
STORAGE    (
        INITIAL          2M
        NEXT             1M
        MINEXTENTS       1
        MAXEXTENTS       UNLIMITED
        PCTINCREASE      0
        BUFFER_POOL      DEFAULT
       )
LOGGING 
NOCOMPRESS 
NOCACHE
PARALLEL ( DEGREE DEFAULT INSTANCES DEFAULT )
MONITORING;


CREATE INDEX PRODBMDB.JOURNAL1 ON PRODBMDB.JOURNAL
(DATETIME)
LOGGING
TABLESPACE USERSBIG
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
        INITIAL          64K
        NEXT             1M
        MINEXTENTS       1
        MAXEXTENTS       UNLIMITED
        PCTINCREASE      0
        BUFFER_POOL      DEFAULT
       )
NOPARALLEL;


CREATE INDEX PRODBMDB.JOURNAL2 ON PRODBMDB.JOURNAL
(MANDATORID, INSTITUTEID, WORKSTATIONID)
LOGGING
TABLESPACE USERSBIG
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
        INITIAL          64K
        NEXT             1M
        MINEXTENTS       1
        MAXEXTENTS       UNLIMITED
        PCTINCREASE      0
        BUFFER_POOL      DEFAULT
       )
NOPARALLEL;


CREATE INDEX PRODBMDB.JOURNAL3 ON PRODBMDB.JOURNAL
(SESSIONID, TRANSACTIONNUMBER)
LOGGING
TABLESPACE USERSBIG
PCTFREE    10
INITRANS   2
MAXTRANS   255
STORAGE    (
        INITIAL          64K
        NEXT             1M
        MINEXTENTS       1
        MAXEXTENTS       UNLIMITED
        PCTINCREASE      0
        BUFFER_POOL      DEFAULT
       )
NOPARALLEL;

这是分区表的脚本。迁移的目标。

CREATE TABLE PRODBMDB.JOURNAL1
(
  ID                  VARCHAR2(32 BYTE)         NOT NULL,
  GATEWAYID           VARCHAR2(128 BYTE)        DEFAULT NULL,
  WORKSTATIONID       VARCHAR2(128 BYTE),
  MANDATORID          NUMBER(19)                DEFAULT NULL,
  INSTITUTEID         NUMBER(19)                DEFAULT NULL,
  SUBSIDIARYID        NUMBER(19)                DEFAULT NULL,
  ACQUIRERID          NUMBER(19)                DEFAULT NULL,
  DATETIME            TIMESTAMP(6)              NOT NULL,
  SESSIONID           VARCHAR2(32 BYTE),
  AUTHORIZETSTAMP     TIMESTAMP(6),
  TRANSACTIONNUMBER   NUMBER(19)                NOT NULL,
  TRANSACTIONSTEPNR   NUMBER(19),
  CLIENTTRXNUM        NUMBER(19),
  HOSTTRXNUM          VARCHAR2(32 BYTE),
  METHOD              VARCHAR2(64 BYTE),
  ACTIONTYPE          INTEGER                   NOT NULL,
  ACTIONSUBTYPE       INTEGER,
  FRAUDRESULT         INTEGER,
  FRAUDSCORE          INTEGER,
  CUSTOMERID          VARCHAR2(32 BYTE),
  ROUTINGCODE         VARCHAR2(50 BYTE),
  ACCOUNTNUMBER       VARCHAR2(50 BYTE),
  CARDSEQUENCENUMBER  VARCHAR2(2 BYTE),
  AMOUNT              NUMBER(19),
  CURRENCYCODE        CHAR(3 BYTE),
  COMMANDSOURCE       VARCHAR2(128 BYTE),
  RESPONSECODE        INTEGER,
  EXTRESPONSECODE     INTEGER,
  CANCELREASON        INTEGER,
  DOCUMENTSTATE       INTEGER,
  ACCOUNTINGSTATE     INTEGER,
  CARDSTATE           INTEGER,
  HOSTSTATE           INTEGER,
  EISPH               INTEGER,
  PARTITION           INTEGER,
  CONFIDENTIALS       VARCHAR2(1024 BYTE),
  MEDVIEW             INTEGER,
  MINVIEW             INTEGER,
  LONGVIEW            INTEGER,
  DATA1               RAW(2000),
  DATA2               RAW(2000),
  DATA3               RAW(2000),
  DATA4               RAW(2000),
  DATA5               RAW(2000),
  DATA6               RAW(2000)
)
TABLESPACE USERSBIG
PCTUSED    0
PCTFREE    10
INITRANS   10
MAXTRANS   255
STORAGE    (
        INITIAL          2M
        NEXT             1M
        MINEXTENTS       1
        MAXEXTENTS       UNLIMITED
        PCTINCREASE      0
       )
LOGGING
PARTITION BY LIST (ACTIONTYPE)
(  
  PARTITION PART1 VALUES (1)
    LOGGING
        NOCOMPRESS 
    TABLESPACE USERSBIG
    PCTFREE    10
    INITRANS   10
    MAXTRANS   255
    STORAGE    (
            INITIAL          2M
            NEXT             2M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            BUFFER_POOL      DEFAULT
           ),  
  PARTITION PART2 VALUES (2)
    LOGGING
    NOCOMPRESS 
    TABLESPACE USERSBIG
    PCTFREE    10
    INITRANS   10
    MAXTRANS   255
    STORAGE    (
            INITIAL          2M
            NEXT             2M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            BUFFER_POOL      DEFAULT
           ),  
  PARTITION PART3 VALUES (3)
    LOGGING
    NOCOMPRESS 
    TABLESPACE USERSBIG
    PCTFREE    10
    INITRANS   10
    MAXTRANS   255
    STORAGE    (
            INITIAL          2M
            NEXT             2M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            BUFFER_POOL      DEFAULT
           ),  
  PARTITION PART4 VALUES (5)
    LOGGING
    NOCOMPRESS 
    TABLESPACE USERSBIG
    PCTFREE    10
    INITRANS   10
    MAXTRANS   255
    STORAGE    (
            INITIAL          2M
            NEXT             2M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            BUFFER_POOL      DEFAULT
           ),  
  PARTITION PART5 VALUES (10)
    LOGGING
    NOCOMPRESS 
    TABLESPACE USERSBIG
    PCTFREE    10
    INITRANS   10
    MAXTRANS   255
    STORAGE    (
            INITIAL          2M
            NEXT             2M
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            BUFFER_POOL      DEFAULT
           )
)
NOCOMPRESS 
NOCACHE
PARALLEL ( DEGREE DEFAULT INSTANCES DEFAULT )
MONITORING;

这是我用来迁移数据的脚本

insert into journal1
select * from journal

当我检查表journal1中的数据时,数据插入成功但没有分区。任何人都有线索为什么会这样?

1 个答案:

答案 0 :(得分:2)

DBA_TABLES.NUM_ROWS是收集优化程序统计信息时计算的行数。它不一定代表实际的行数。不管  在表中插入的内容,在收集统计信息之前,查询将如下所示:

select partition_name, num_rows
from dba_tab_partitions
where table_name = 'JOURNAL1';

PARTITION_NAME  NUM_ROWS
--------------  --------
PART1   
PART2   
PART3   
PART4   
PART5   

收集统计信息将设置行数,但数字不会保持最新:

begin
    dbms_stats.gather_table_stats('PRODBMDB', 'JOURNAL1');
end;
/

select partition_name, num_rows
from dba_tab_partitions
where table_name = 'JOURNAL1';

PARTITION_NAME  NUM_ROWS
--------------  --------
PART1                  0
PART2                  0
PART3                  0
PART4                  0
PART5                  0