Problem exchanging partitions using range partitioning

I have a range-partitioned table. Here's a cut down version....
CREATE TABLE MY_TABLE
   (     VALUE           NUMBER,
     PARTITION_KEY      NUMBER
  PARTITION BY RANGE ("PARTITION_KEY")
(PARTITION "P1"  VALUES LESS THAN (2),
  PARTITION "P2"  VALUES LESS THAN (3),
  PARTITION "P3"  VALUES LESS THAN (4),
  PARTITION "P4"  VALUES LESS THAN (5),
  PARTITION "P5"  VALUES LESS THAN (6),
  PARTITION "P6"  VALUES LESS THAN (7),
  PARTITION "P7"  VALUES LESS THAN (8));For the process I'm working on, I want to be able to:
- create a table as a copy of one of the partitions
- do some processing on that table
- exchange the updated table back into the partitioned table
I can achieve this as follows....
CREATE TABLE MY_TABLE_COPY_P7 AS (SELECT * FROM MY_TABLE WHERE PARTITION_KEY = 7);
... do processing ...
ALTER TABLE MY_TABLE DROP PARTITION P7;
ALTER TABLE MY_TABLE ADD PARTITION P7 VALUES LESS THAN (8);
ALTER TABLE MY_TABLE EXCHANGE PARTITION P7 WITH TABLE MY_TABLE_COPY INCLUDING INDEXES;However, this only works if the partition I'm adding back in is the highest partition.
If I try do take out one of the middle partitions, then add it back I get an error:
SQL] ALTER TABLE MY_TABLE ADD PARTITION P5 VALUES LESS THAN (6);
ALTER TABLE MY_TABLE ADD PARTITION P5 VALUES LESS THAN (6)
ERROR at line 1:
ORA-14074: partition bound must collate higher than that of the last partitionAny ideas on how I can exchange one of the middle partitions with having to first drop the higher ones?
Btw, I have to use range partitioning as we're using spatial, which only supports range partitioning.
Cheers,

Actually, you can do the exchange partition thing with 8i and over. After creating my_table from your script, I did:
SQL> INSERT INTO my_table VALUES (1,7.5);
1 row created.
SQL> INSERT INTO my_table VALUES (2, 7.2);
1 row created.
SQL> INSERT INTO my_table VALUES (3,7.7);
1 row created.
SQL> CREATE TABLE my_tab_tmp AS
  2  SELECT * FROM my_table
  3  WHERE 1=2;
Table created.
SQL> ALTER TABLE my_table EXCHANGE PARTITION P7 WITH TABLE my_tab_tmp;
Table altered.
SQL> SELECT * FROM my_tab_tmp;
     VALUE PARTITION_KEY
         1           7.5
         2           7.2
         3           7.7
SQL> SELECT * FROM my_table;
no rows selected
SQL> UPDATE my_tab_tmp
  2  set value = value * 20;
3 rows updated.
SQL> COMMIT;
Commit complete.
SQL> ALTER TABLE my_table EXCHANGE PARTITION P7 WITH TABLE my_tab_tmp;
Table altered.
SQL> SELECT * FROM my_tab_tmp;
no rows selected
SQL> SELECT * FROM my_table;
     VALUE PARTITION_KEY
        20           7.5
        40           7.2
        60           7.7You will, of course, need to re-build any global indexes on my_table.
When you first create my_tab_tmp, you should also create indexes to match any local indexes on the partitions, then do the exchange partition using the INCLUDING INDEXES clause. You could also skip creating the indexes and then re-create them after exchanging the updated table with the partition.
Note that none of this will work if you are changing values of partition_key so thatthey fall out of the range for the partition.
HTH
John

Similar Messages

  • Trying to convert Interval Partitioned Table to Range..Exchange Partition..

    Requirement:
    Replace Interval partitioned Table by Range Partitioned Table
    DROP TABLE A;
    CREATE TABLE A
       a              NUMBER,
       CreationDate   DATE
    PARTITION BY RANGE (CreationDate)
       INTERVAL ( NUMTODSINTERVAL (30, 'DAY') )
       (PARTITION P_FIRST
           VALUES LESS THAN (TIMESTAMP ' 2001-01-01 00:00:00'));
    INSERT INTO A
         VALUES (1, SYSDATE);
    INSERT INTO A
         VALUES (1, SYSDATE - 30);
    INSERT INTO A
         VALUES (1, SYSDATE - 60);I need to change this Interval Partitioned Table to a Range Partitioned Table. Can I do it using EXCHANGE PARTITION. As if I use the conventional way of creating another Range Partitioned table and then :
    DROP TABLE A_Range
    CREATE TABLE A_Range
    a NUMBER,
    CreationDate DATE
    PARTITION BY RANGE (CreationDate)
       (partition MAX values less than (MAXVALUE));
    Insert  /*+ append */  into A_Range Select * from A; --This Step takes very very long..Trying to cut it short using Exchange Partition.Problems:
    I can't do
    ALTER TABLE A_Range
      EXCHANGE PARTITION MAX
      WITH TABLE A
      WITHOUT VALIDATION;
    ORA-14095: ALTER TABLE EXCHANGE requires a non-partitioned, non-clustered table
    This is because both the tables are partitioned. So it does not allow me.
    If I do instead :
    create a non partitioned table for exchanging the data through partition.
      Create Table A_Temp as Select * from A;
       ALTER TABLE A_Range
      EXCHANGE PARTITION MAX
      WITH TABLE A_TEMP
      WITHOUT VALIDATION;
      select count(*) from A_Range partition(MAX);
    -Problem is that all the data goes into MAX Partition.
    Even after creating a lot of partitions by Splitting Partitions, still the data is in MAX Partition only.
    So:
    -- Is it that we can't Replace an Interval Partitioned Table by Range Partitioned Table using EXCHANGE PARTITION. i.e. We will have to do Insert into..
    -- We can do it but I am missing something over here.
    -- If all the data is in MAX Partition because of "WITHOUT VALIDATION" , can we make it be redistributed in the right kind of range partitions.

    You will need to pre-create the partitions in a_range, then exchange them one by one from a to a tmp then then to arange. Using your sample (thanks for proviing the code by the way).
    SQL> CREATE TABLE A
      2  (
      3     a              NUMBER,
      4     CreationDate   DATE
      5  )
      6  PARTITION BY RANGE (CreationDate)
      7     INTERVAL ( NUMTODSINTERVAL (30, 'DAY') )
      8     (PARTITION P_FIRST
      9         VALUES LESS THAN (TIMESTAMP ' 2001-01-01 00:00:00'));
    Table created.
    SQL> INSERT INTO A VALUES (1, SYSDATE);
    1 row created.
    SQL> INSERT INTO A VALUES (1, SYSDATE - 30);
    1 row created.
    SQL> INSERT INTO A VALUES (1, SYSDATE - 60);
    1 row created.
    SQL> commit;
    Commit complete.You can find the existing partitions form a using:
    SQL> select table_name, partition_name, high_value
      2  from user_tab_partitions
      3  where table_name = 'A';
    TABLE_NAME PARTITION_NAME HIGH_VALUE
    A          P_FIRST        TO_DATE(' 2001-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
    A          SYS_P44        TO_DATE(' 2013-01-28 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
    A          SYS_P45        TO_DATE(' 2012-12-29 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
    A          SYS_P46        TO_DATE(' 2012-11-29 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAYou can then create table a_range with the apporopriate partitions. Note that you may need to create additional partitions in a_range because interval partitioning does not create partitions that it has no data for, even if that leaves "holes" in the partitioning scheme. So, based on the above:
    SQL> CREATE TABLE A_Range (
      2     a NUMBER,
      3     CreationDate DATE)
      4  PARTITION BY RANGE (CreationDate)
      5     (partition Nov_2012 values less than (to_date('30-nov-2012', 'dd-mon-yyyy')),
      6      partition Dec_2012 values less than (to_date('31-dec-2012', 'dd-mon-yyyy')),
      7      partition Jan_2013 values less than (to_date('31-jan-2013', 'dd-mon-yyyy')),
      8      partition MAX values less than (MAXVALUE));
    Table created.Now, create a plain table to use in the exchanges:
    SQL> CREATE TABLE A_tmp (
      2     a              NUMBER,
      3     CreationDate   DATE);
    Table created.and exchange all of the partitions:
    SQL> ALTER TABLE A
      2    EXCHANGE PARTITION sys_p44
      3    WITH TABLE A_tmp;
    Table altered.
    SQL> ALTER TABLE A_Range
      2    EXCHANGE PARTITION jan_2013
      3    WITH TABLE A_tmp;
    Table altered.
    SQL> ALTER TABLE A
      2    EXCHANGE PARTITION sys_p45
      3    WITH TABLE A_tmp;
    Table altered.
    SQL> ALTER TABLE A_Range
      2    EXCHANGE PARTITION dec_2012
      3    WITH TABLE A_tmp;
    Table altered.
    SQL> ALTER TABLE A
      2    EXCHANGE PARTITION sys_p46
      3    WITH TABLE A_tmp;
    Table altered.
    SQL> ALTER TABLE A_Range
      2    EXCHANGE PARTITION nov_2012
      3    WITH TABLE A_tmp;
    Table altered.
    SQL> select * from a;
    no rows selected
    SQL> select * from a_range;
             A CREATIOND
             1 23-NOV-12
             1 23-DEC-12
             1 22-JAN-13John

  • Problems with Partition pruning using LIST option in 9i

    I am declaring the following partitions on a fact table and when
    I do an explain plan on the following SELECT statements it is
    doing a full table scan on the fact table. However if I use
    the "PARTITION" statement in the FROM clause it picks up the
    correct partition and runs great. I have used the analyze
    command and dbms_utility.analyze_schema command on all tables
    and indexes. I had simaliar problems when partitioning with the
    RANGE options too. I have looked through all of the INIT file
    parameters and don't see anything obvious. Is there something I
    am missing?
    Any help would be appreciated!
    Thanks,
    Bryan
    Facttable create statement....
    CREATE TABLE FactTable (
    ProductGID INTEGER NULL,
    CustomerGID INTEGER NULL,
    OrganizationGID INTEGER NULL,
    TimeGID INTEGER NULL,
    FactValue NUMBER NOT NULL,
    ModDate DATE NULL,
    CombinedGID INTEGER NOT NULL)
    PARTITION BY LIST (CombinedGID)
    (PARTITION sales1 VALUES(9999101),
    PARTITION sales2 VALUES(9999102),
    PARTITION sales3 VALUES(9999103),
    PARTITION model1 VALUES(9999204),
    PARTITION model2 VALUES(9999205),
    PARTITION model3 VALUES(9999206));
    Select statement....that is causing a full table scan.....the
    *tc tables are the equivelent to dimension tables in a star
    schema.
    SELECT tco.parentgid, tcc.parentgid, tcp.parentgid, sum
    (factvalue)
    FROM facttable f, custtc tcc, timetc tct, prodtc tcp, orgtc tco
    WHERE
    tco.childgid = f.organizationgid
    AND tco.parentgid = 18262
    AND tcc.childgid = f.customergid
    AND tcc.parentmembertypegid = 16
    AND tcp.childgid = f.productgid
    AND tcp.parentmembertypegid = 7
    AND tct.childgid = f.timegid
    AND tct.parentgid = 1009
    GROUP BY tco.parentgid, tcc.parentgid, tcp.parentgid;
    Select statement that works great....
    SELECT tco.parentgid, tcc.parentgid, tcp.parentgid, sum
    (factvalue)
    FROM facttable partition(sales1) f, custtc tcc, timetc tct,
    prodtc tcp, orgtc tco
    WHERE
    tco.childgid = f.organizationgid
    AND tco.parentgid = 18262
    AND tcc.childgid = f.customergid
    AND tcc.parentmembertypegid = 16
    AND tcp.childgid = f.productgid
    AND tcp.parentmembertypegid = 7
    AND tct.childgid = f.timegid
    AND tct.parentgid = 1009
    GROUP BY tco.parentgid, tcc.parentgid, tcp.parentgid;

    Hi Hoek,
    the DB version is 10.2 (italian version, then SET is correct).
    ...there's something strange: now I can INSERT rows but I can't update them!
    I'm using this command string:
    UPDATE TW_E_CUSTOMER_UNIFIED SET END_VALIDITY_DATE = TO_DATE('09-SET-09', 'DD-MON-RR') WHERE
    id_customer_unified = '123' and start_validity_date = TO_DATE('09-SET-09', 'DD-MON-RR');
    And this is the error:
    Error SQL: ORA-14402: updating partition key column would cause a partition change
    14402. 00000 - "updating partition key column would cause a partition change"
    *Cause:    An UPDATE statement attempted to change the value of a partition
    key column causing migration of the row to another partition
    *Action:   Do not attempt to update a partition key column or make sure that
    the new partition key is within the range containing the old
    partition key.
    I think that is impossible to use a PARTITION/SUBPARTITION like that: in fact the update of "END_VALIDITY_DATE" cause a partition change.
    Do u agree or it's possible an update on a field that implies a partition change?
    Regards Steve

  • How to use Exchange partition

    Hi All,
    I have a requirement like .. i have to insert the data from partition table to unpartition table like temp table. by googling i came to know about Exchange partition. by using Exchange partition we can dump temp table to partition table but i don't know how to copy the data from partition table to temp table. following script am using.
    ALTER TABLE abc_partition
    EXCHANGE PARTITION P_2011_1115 WITH TABLE abc_tmp
    INCLUDING INDEXES
    WITHOUT VALIDATION;
    And again i have created a partition table and i ran below query
    ALTER TABLE abc_tmp
    EXCHANGE PARTITION P_2011_1115 WITH TABLE abc_partition
    INCLUDING INDEXES
    WITHOUT VALIDATION;
    but i was getting an error like partition ALTER TABLE EXCHANGE requires a non-partitioned, non-clustered table
    Thanks
    Sree
    Edited by: 874823 on Apr 30, 2012 2:01 AM

    In that case, you need to follow these basic steps.
    1. Use a CTAS (Create Table as Select) to create the staging table. This table's structure needs to match that of the partition table - be that a hash or index organised structure. The columns need to be in the same order, and of the same data type. Not null constraints need to be applied to the applicable columns. If you have manually set storage clauses (e.g. PCTFREE for example) for the partition table, the same needs to be applied to the staging table.
    A CTAS would look something as follows:
    create table staging_table(
      col1 not null,
      col2 null,
      col3 null
    ) nologging as
    select
      some_col,
      some_other_column,
      third_column
    from some_other_data2. The next step is to add the required indexes to the staging table - as that table needs to match the structure of the partitioned table. So the staging table needs to have the same index structures as local partition indexes of the partition table.
    3. The actual partition exchange can now happen. The data is not actually exchanged. Ownership of the data changes. The data blocks (for data and indexes) owned by the staging table, is now owned by that partition in the partition table. Likewise the staging table now owns the data and indexes of the partition.
    4. The last step is cleaning up - dropping and purging the staging table (assuming that you no longer have a need for it).
    The above steps can be fully automated (for any partition table) by developing a generic PL/SQL interface library that performs these steps. Additional features such as parallel processing and tablespaces to use for the staging table and indexes can also considered for such a PL/SQL interface.

  • Exchange Partition Problem

    Hi,
    I am trying to create a partition table for a non parttition table.
    create table dept_test partition by list(deptno)
    (partition p10 values(10),
    partition p20 values(20),
    partition p30 values(30),
    partition p40 values(40))
    as select * from dept where 1=0;
    create table dept1
    as
    select * from dept;
    alter table DEPT_TEST
    exchange partition p10
    with table dept1
    WITHOUT VALIDATION;
    BEGIN
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P10',33);
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P20',33);
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P30',33);
    EXEC dbms_stats.gather_table_stats('usr','DEPT_TEST','P40',33);
    END;
    select * from dba_tab_partitions where table_name='DEPT_TEST';
    SELECT * FROM DEPT_TEST WHERE DEPTNO=10;
    SELECT * FROM DEPT_TEST WHERE DEPTNO=20;
    In the dba_tab_partitions,row count for p10 is showing as 4. when i ran the query for the value 10 ,i got 4 row but for 20 no rows.
    Can you please tell me what is the problem?
    Thanks.

    Partition exchange moved all the data to partition p10. Partitions p20, p30 and p40 are empty. Evaluating condition WHERE DEPTNO = 10 optimizer relys on the partition definition VALUES(10). It's enough to do partition pruning only to satisfy the condition. The same partition pruning takes place for the condition DEPTNO = 20, but partition p20 is empty and the query returns no rows.
    SQL> set autotrace on explain
    SQL> SELECT * FROM DEPT_TEST WHERE DEPTNO=10;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    Execution Plan
    Plan hash value: 2891473902
    | Id  | Operation             | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT      |           |     1 |    20 |     3   (0)| 00:00:01 |       |       |
    |   1 |  PARTITION LIST SINGLE|           |     1 |    20 |     3   (0)| 00:00:01 |     1 | 1 |
    |   2 |   TABLE ACCESS FULL   | DEPT_TEST |     1 |    20 |     3   (0)| 00:00:01 |     1 | 1 |
    SQL> SELECT * FROM DEPT_TEST WHERE DEPTNO=20;
    no rows selected
    Execution Plan
    Plan hash value: 2891473902
    | Id  | Operation             | Name      | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT      |           |     1 |    30 |     2   (0)| 00:00:01 |       |       |
    |   1 |  PARTITION LIST SINGLE|           |     1 |    30 |     2   (0)| 00:00:01 |     2 | 2 |
    |   2 |   TABLE ACCESS FULL   | DEPT_TEST |     1 |    30 |     2   (0)| 00:00:01 |     2 | 2 |
    ---------------------------------------------------------------------------------------------------Regards,
    Dima
    Message was edited by:
    dimacit

  • ORA-02266: unique/primary keys - error while using Exchange Partition

    Hi All,
    While using EXCHANGE PARTITION statement as given below,
    ALTER TABLE SOURCE_TABLE EXCHANGE PARTITION PRT_EXCG_PRTN WITH TABLE TARGET_TABLE
    we are getting this error,
    ORA-02266: unique/primary keys in table referenced by enabled foreign keys
    However, there are no tables have foreign keys referring this TARGET_TABLE, we checked this by referring
    USER_CONSTRAINTS table, it has only primary key and NOT NULL constraints.
    SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME like 'TARGET_TABLE';
    We are using the following version,
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    PL/SQL Release 9.2.0.6.0 - Production
    CORE     9.2.0.6.0     Production
    TNS for IBM/AIX RISC System/6000: Version 9.2.0.6.0 - Production
    NLSRTL Version 9.2.0.6.0 - Production
    Is it due to any error in our end or it could be a bug in Oracle and should we go for any patch updation ?
    Please guide us to resolve this error as soon as possible, thank you.
    Regards,
    Deva

    *** Duplicate Post ***
    Please Ignore.

  • How to use "exchange partition" as performance trick?

    Hi,
    having a partitioned table in Oracle 10g release 2, I am searching for a performant to reload partitions completely.
    I heard about the possibility to load the new data (== complete partition which shall replace existing partition data) completely into a temporary partition and then just to exchange the partitions (throw away the old one and replace it with the new one). This (I was told - and it sounds good to me) is a most performant way of updating the complete data of one partition.
    Yet it is unclear to me how to load the new data (which automatically would be inserted in the partition which it shall replace).
    So is this possibility existing at all?
    Any link to an example?
    Best regards from sunny Black Forrest,
    Mattin

    Hi Martin,
    the procedere would be something like
    create table tmp_berichtswerte as select * from berichtswerte where 1=0;
    Populate the temp table
    alter table berichtswerte exchange partition brw_p200109 with table tmp_berichtswerte;
    Rebuild the indexes on that partition (and the global indexes on the table)P.S. Sunny? Right now? your are kidding!

  • Oracle Exchange partition feature not working as expected?

    I used the Exchange Partition feature to swap segments between 2 tables- one Partitioned, and one Non-Partitioned. The exchange went well. However, all the data in the partitioned table has gone to the partition which stores the maxbound values.
    Any ideas if this is the default behavior or have i missed out something?
    /** actual table names changed due to client confidentiality issues */
    -- Drop the 2 intermediate tables if they already exist
    drop table ordered_inv_bkp cascade constraints ;
    drop table ordered_inv_t cascade constraints ;
    1st create a Non-Partitioned Table from ORDERED_INV and then add the primary key and unique index(s):
    create table ordered_inv_bkp as select * from ordered_inv ;
    alter table ordered_inv_bkp add constraint ordinvb_pk primary key (ordinv_id) ;
    create unique index ordinv_scinv_uix on ordered_inv_bkp(
    SCP_ID ASC,
    INV_ID ASC,
    ANATLOC_ID ASC,
    SOI_ID ASC,
    CANCEL_TS ASC );
    -- Next, we have to create a partitioned table ORDERED_INV_T with a similar
    -- structure as ORDERED_INV.
    -- This is a bit tricky, and involves a pl/sql code
    declare
    l_dt_start DATE;
    l_ptn VARCHAR2(50);
    cnt PLS_INTEGER;
    l_cnt_initial PLS_INTEGER;
    ts_name VARCHAR2(50);
    l_sql VARCHAR2(10000);
    ts_indx VARCHAR2(100);
    l_num_errors NUMBER ;
    l_num_errors_ok NUMBER ;
    l_user_name VARCHAR2(50) ;
    l_sysdate VARCHAR2(50);
    l_cnt_script PLS_INTEGER ;
    BEGIN
    SELECT COUNT(*) INTO cnt FROM user_TABLES
    WHERE TABLE_NAME='ORDERED_INV_T';
    IF cnt=0 THEN
    l_sql:= 'CREATE TABLE ORDERED_INV_T
    PARTITION BY RANGE (ORDINV_TIME)
    ( PARTITION TP_ORDINV_MAX VALUES LESS THAN (MAXVALUE)
    TABLESPACE TEST_TPT_DATA
    ENABLE ROW MOVEMENT
    AS SELECT * FROM ORDERED_INV WHERE 1=0 ';
    EXECUTE IMMEDIATE l_sql;
    -- Add section to set default values for the intermediate table OL_ORDERED_INV_T
    FOR crec_cols IN (
    SELECT u.column_name ,u.nullable, u.data_default,u.table_name
    FROM USER_TAB_COLUMNS u WHERE
    u.table_name ='ORDERED_INV' AND
    u.data_default IS NOT NULL )
    LOOP
    l_sql:= 'ALTER TABLE ORDERED_INV_T MODIFY '||crec_cols.column_name||' DEFAULT '||crec_cols.data_default;
    -- dbms_output.put_line('chk data default => ' || l_sql) ;
    EXECUTE IMMEDIATE l_sql;
    END LOOP;
    END IF;
    -- Split partition to create more partitions
    select TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') into l_sysdate from dual;
    DBMS_OUTPUT.PUT_LINE ('Finding oldest value at ' || l_sysdate) ;
    EXECUTE IMMEDIATE 'SELECT NVL(TRUNC(MIN(OL_ORDINV_TIME),''MONTH''),TRUNC(SYSDATE,''MONTH''))
    FROM ORDERED_INV' INTO l_dt_start;
    select TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') into l_sysdate from dual;
    DBMS_OUTPUT.PUT_LINE ('Started creating partitions at ' || l_sysdate) ;
    LOOP
    EXIT WHEN l_dt_start > ADD_MONTHS(TRUNC(SYSDATE,'MONTH'),1);
    l_ptn:='tp_ordinv_'|| TO_CHAR(l_dt_start,'YYYYMM');
    l_sql:= 'ALTER TABLE ORDERED_INV_T
    split partition TP_ORDINV_MAX at (TO_DATE('''|| TO_CHAR(ADD_MONTHS(l_dt_start,12),'YYYYMM') ||''',''YYYYMM''))
    into ( partition '||l_ptn||' , partition TP_ORDINV_MAX)';
    execute immediate l_sql;
    l_dt_start:=add_months(l_dt_start,12);
    END LOOP;
    END;
    -- Also, add indexes to this table
    alter table ORDERED_INV_T add constraint ordinvt_pk primary key (ordinv_id) ;
    create unique index ordinvt_uix on ordered_inv_t(
    SCP_ID ASC,
    INV_ID ASC,
    ANATLOC_ID ASC,
    SOI_ID ASC,
    CANCEL_TS ASC );
    -- Next, use exchange partition for actual swipe
    -- Between ordered_inv_t and ordered_inv_bkp
    -- Analyze both tables : ordered_inv_t and ordered_inv_bkp
    BEGIN
    DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'HENRY220', TABNAME => 'ORDERED_INV_T');
    DBMS_STATS.GATHER_TABLE_STATS(OWNNAME => 'HENRY220', TABNAME =>'ORDERED_INV_BKP');
    END;
    SET TIMING ON;
    ALTER TABLE ordered_inv_t
    EXCHANGE PARTITION TP_ORDINV_MAX
    WITH TABLE ordered_inv_bkp
    WITHOUT VALIDATION
    UPDATE GLOBAL INDEXES;
    -- Check query :
    select partition_name, num_rows, high_value from user_tab_partitions where table_name = 'ORDERED_INV_T' ;
    These are the results:
    TP_ORDINV_199801 0 TO_DATE(' 1999-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_199901 0 TO_DATE(' 2000-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200001 0 TO_DATE(' 2001-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200101 0 TO_DATE(' 2002-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200201 0 TO_DATE(' 2003-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200301 0 TO_DATE(' 2004-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200401 0 TO_DATE(' 2005-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200501 0 TO_DATE(' 2006-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200601 0 TO_DATE(' 2007-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200701 0 TO_DATE(' 2008-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200801 0 TO_DATE(' 2009-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_200901 0 TO_DATE(' 2010-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_201001 0 TO_DATE(' 2011-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_201101 0 TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_201201 0 TO_DATE(' 2013-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
    TP_ORDINV_MAX 24976 MAXVALUE
    Pay attention to the last record

    >
    used the Exchange Partition feature to swap segments between 2 tables- one Partitioned, and one Non-Partitioned. The exchange went well. However, all the data in the partitioned table has gone to the partition which stores the maxbound values.
    >
    That isn't possible. The data in the partition before the exchange could only have gone to the non-partitioned table.
    Please edit you post and add \ tags on the lines before and after your code to preserve formatting. See the FAQ for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Re: exchange partition on weekly partition

    We have divided month in 4 week partitions Week 1 start from date 2 to 8, Week2 start from 9 to 15, Week3 start from 16 to 22 and Week4 start from 23 to 1st of coming month.
    Tables has huge data (some tables size in TB). Can exchange partition will work on it or I have to change it to daily partition (with huge data)?
    Yes - exchange partition will work on it. As I said above:
    EXCHANGE PARTITION just exchanges two 'like' partitions so doesn't care what time period the partitions represent (daily, weekly, monthly, etc).
    That allows you to EXCHANGE one 'weekly' partition with a temp table.
    But you said you are loading data daily:
    We are loading data in our dataware house on daily basis from temp to stage and fact tables through insert command
    So you don't have a weeks worth of data to exchange; you have a 'days' worth of data. That can only be EXCHANGED with a partition that is intended to hold a days worth of data.
    If you are manually adding partitions to your current table then just begin manually add DAILY partitions instead of adding weekly ones. Then you can do a simple daily EXCHANGE to load the data.
    Or you could REDEFINE your existing table to use daily partitions by just defining partitions that correspond to your existing weekly ones to hold your current data and then daily partitions for your new data.
    CREATE TABLE SCOTT.PARTITION_DAILY_TEST
      ID       NUMBER(10),
      MY_DATE  DATE
    PARTITION BY RANGE (MY_DATE)
    INTERVAL( NUMTODSINTERVAL(1,'DAY'))
      PARTITION P_201204_WEEK1 VALUES LESS THAN (TO_DATE(' 2012-04-08 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201204_WEEK2 VALUES LESS THAN (TO_DATE(' 2012-04-16 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201204_WEEK3 VALUES LESS THAN (TO_DATE(' 2012-04-23 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201204_WEEK4 VALUES LESS THAN (TO_DATE(' 2012-05-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
      PARTITION P_201205_WEEK1 VALUES LESS THAN (TO_DATE(' 2012-05-08 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    That table definition above defines specific partitions for existing data but tells Oracle to CREATE and USE daily partitions for new data.
    Then you can use EXCHANGE PARTITION (via a work tablel) to move data from your current table partitions to the new table partitions.

    If you are manually adding partitions to your current table then just begin manually add DAILY partitions instead of adding weekly ones. Then you can do a simple daily EXCHANGE to load the data.
    Or you could REDEFINE your existing table to use daily partitions by just defining partitions that correspond to your existing weekly ones to hold your current data and then daily partitions for your new data.
    rp0428,
    Just for confirmation can we add daily partition instead of weekly in our existing table for future data and current data will remain in weekly partition.

  • Problems with partition tables

    Hi all,
    I've got some problems with partition tables. The script at the bottom run but when I wanna insert some values it returns me an error
    (ORA-06550: line 1, column 30: PL/SQL: ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 1, column 7: PL/SQL: SQL Statement ignored)
    and I can't understand why!
    There's something incorrect in the script or not?
    Please help me
    Thanks in advance
    Steve
    CREATE TABLE TW_E_CUSTOMER_UNIFIED
    ID_CUSTOMER_UNIFIED VARCHAR2 (27) NOT NULL ,
    START_VALIDITY_DATE DATE NOT NULL ,
    END_VALIDITY_DATE DATE ,
    CUSTOMER_STATUS VARCHAR2 (255)
    PARTITION BY RANGE (START_VALIDITY_DATE)
    SUBPARTITION BY LIST (END_VALIDITY_DATE)
    PARTITION M200909 VALUES LESS THAN (TO_DATE('20091001','YYYYMMDD'))
    (SUBPARTITION M200909_N VALUES (NULL), SUBPARTITION M200909_NN VALUES (DEFAULT)),
    PARTITION M200910 VALUES LESS THAN (TO_DATE('20091101','YYYYMMDD'))
    (SUBPARTITION M200910_N VALUES (NULL), SUBPARTITION M200910_NN VALUES (DEFAULT)),
    PARTITION M200911 VALUES LESS THAN (TO_DATE('20091201','YYYYMMDD'))
    (SUBPARTITION M200911_N VALUES (NULL), SUBPARTITION M200911_NN VALUES (DEFAULT)),
    PARTITION M200912 VALUES LESS THAN (TO_DATE('20100101','YYYYMMDD'))
    (SUBPARTITION M200912_N VALUES (NULL), SUBPARTITION M200912_NN VALUES (DEFAULT)),
    PARTITION M201001 VALUES LESS THAN (TO_DATE('20100201','YYYYMMDD'))
    (SUBPARTITION M201001_N VALUES (NULL), SUBPARTITION M201001_NN VALUES (DEFAULT)),
    PARTITION M201002 VALUES LESS THAN (TO_DATE('20100301','YYYYMMDD'))
    (SUBPARTITION M201002_N VALUES (NULL), SUBPARTITION M201002_NN VALUES (DEFAULT)),
    PARTITION M210001 VALUES LESS THAN (MAXVALUE))
    (SUBPARTITION M210001_N VALUES (NULL), SUBPARTITION M210001_NN VALUES (DEFAULT))
    ;

    Hi Hoek,
    the DB version is 10.2 (italian version, then SET is correct).
    ...there's something strange: now I can INSERT rows but I can't update them!
    I'm using this command string:
    UPDATE TW_E_CUSTOMER_UNIFIED SET END_VALIDITY_DATE = TO_DATE('09-SET-09', 'DD-MON-RR') WHERE
    id_customer_unified = '123' and start_validity_date = TO_DATE('09-SET-09', 'DD-MON-RR');
    And this is the error:
    Error SQL: ORA-14402: updating partition key column would cause a partition change
    14402. 00000 - "updating partition key column would cause a partition change"
    *Cause:    An UPDATE statement attempted to change the value of a partition
    key column causing migration of the row to another partition
    *Action:   Do not attempt to update a partition key column or make sure that
    the new partition key is within the range containing the old
    partition key.
    I think that is impossible to use a PARTITION/SUBPARTITION like that: in fact the update of "END_VALIDITY_DATE" cause a partition change.
    Do u agree or it's possible an update on a field that implies a partition change?
    Regards Steve

  • Reverting exchanged partitions

    Hi All,
    I am on v11.2.
    In a code, which moves data between tables, I am doing 2 "exchange partition" operations e.g.
    -- Step 1
    alter table T1 exchange partition P1 with table T2 including indexes ;
    -- Step 2
    alter table T3 exchange partition P1 with table T4 including indexes ;These operations will be called from a stored proc with execute immediate.
    Question is, if step1 completes, but step2 fails due to error. In that case, I want to revet back step 1 (i.e. either both steps complete or we should be in a position to run both steps again).
    What can be the best way to do it? using flashback or any other clever thing....
    I can build a programatic solution, that is not a problem e.g. put both the steps in separate begin...exception...end. If second fails, I revert back by runninng same command again (i.e. Step1), so that, T2 will get back its original data etc etc etc
    But I am looking for a better way.
    Thoughts please.
    Thanks in advance

    You can handle something like
    -- Step 1
    alter table T1 exchange partition P1 with table T2 including indexes ;
    -- Step 2
    alter table T3 exchange partition P1 with table T4 including indexes ;
    if count on t4 not equals to 0 then redo step 1
    -- Step 1
    alter table T1 exchange partition P1 with table T2 including indexes ;Edited by: GVR on Nov 1, 2011 8:58 AM

  • Problem defining partition for storing value 0 with new data

    Hi forumers,
    I've a problem with partitioning and need some advices.
    I've a table that will be partitioned by column Process_N which have values from 0 to 50000:
    Process_N between 1 and 29999 represents old data;
    Process_N >= 30000 represents new data;
    Process_N = 0 means the row is not processed yet and so these value represents new data too.
    Can I have a partition for old values (from 1 to 29999) and another partition to store new values (0 + values >= 30000) ? Hou can I define that ?
    Thank you in advance.
    Best Regards,
    Helena

    Helena,
    What's your oracle version? I think it will be better to create 3 partitions usign RANGE partitions (< 1, 2-29999, >=30000 <=50000). Is there a specific reason you want to include 0 and values greater than 29000 in one partition? What the significant difference between 0 and 30000 specially as both represent new data?
    CREATE TABLE my_part_table (
       process_n NUMBER NULL,
       my_data VARCHAR2 (1 BYTE) NULL,
       my_other_data VARCHAR2 (30 BYTE) NULL,
       data_state NUMBER NULL
    TABLESPACE test_data
    PARTITION BY RANGE (process_n)
       (PARTITION partition_0
           VALUES LESS THAN (1)
           TABLESPACE test_data,
       PARTITION partition_2_29999
          VALUES LESS THAN (30000)
          TABLESPACE test_data,
       PARTITION partition_30000
          VALUES LESS THAN (50001)
          TABLESPACE test_data);Regards

  • Exchange Partition

    Hi,
    What happens when :
    1. A query is running on a partition table has millions of records.
    2. Alter table exchange partition ... issued
    Does it completes step (1) first and than it takes (2)step or how it handles? Or will it show wrong result in the query? Please help.

    I have a case for the need to exchange partitions between two range partitioned tables. For example table SALES_HIST contains millions of sales records from the last 5 years range partitioned by fiscal year and month.
    The need arises to add new columns to the table for the current year and going forward. The new columns are meaningless to prior years so the decision is made to move data older than the prior year to separate tables which should retain the fiscal year/month partitioning for performance.
    If we had the ability to exchange partitions between partitioned tables, this would be a simple matter of a series of DDL statements to create the new table(s) and index(es) and then exchange partitions from the current table to the new table. Instead, we are forced to create the table, insert into NEW_TAB /*+ append */ select * from SALES_HIST, alter table sales_hist drop partition, create indexes on new_tab; repeat ad nauseum. And, since the volume of data is huge, we are forced to insert piecemeal else we blow out temp space and drag the system to a crawl.

  • Materialized view on a Partitioned Table (Data through Exchange Partition)

    Hello,
    We have a scenario to create a MV on a Partitioned Table which get data through Exchange Partition strategy. Obviously, with exchange partition snap shot logs are not updated and FAST refreshes are not possible. Also, this partitioned table being a 450 million rows, COMPLETE refresh is not an option for us.
    I would like to know the alternatives for this approach,
    Any suggestions would be appreciated,
    thank you

    From your post it seems that you are trying to create a fast refresh view (as you are creating MV log). There are limitations on fast refresh which is documented in the oracle documentation.
    http://docs.oracle.com/cd/B28359_01/server.111/b28313/basicmv.htm#i1007028
    If you are not planning to do a fast refresh then as already mentioned by Solomon it is a valid approach used in multiple scenarios.
    Thanks,
    Jayadeep

  • Problem in partitioning BI 7.0

    hi friends
          i want to create a partitioning in my cube .
          i use 0FISCPER , 0FISCVARNT , 0FISCYEAR . but partitioning option not allow to me select any radio button. so pls tell me what is a problem ? i use diff Time Char. for this ?
          In this cube have some data , so any problem with this data if i do partitioning ?.
    Regards
    Palav

    Hi
    If cube is having data, you cannot do partitioning. You can do repartitioning in BI 7.0
    Refer this
    http://help.sap.com/saphelp_nw70/helpdata/en/b9/60c041a2236a24e10000000a1550b0/frameset.htm
    Regards
    N Ganesh

Maybe you are looking for

  • Why wont my purchased playlist show up into itunes

    Why wont my purchased playlist show up into itunes

  • Changing the display profile for multiple users at once.

    Is it possible to change the display profile for multiple users at once? We would like ot be able ot add tabs and channels globally, but right now we can anly do it for once user at a time. Also, is it possible to have certain generic display profile

  • Local variable is never used

    I have some code like this:   String s = null;   if (<some test>)     s = "whatever"; }Eclipse tells warns that the local variable s is never used, which is somewhat understandable since the assignment of s is nested. Still, it's annoying. I don't wa

  • Installing older mac`os version

    I would like to install 10.4.6 but have 10.4.8. runnig now. If I use my Macos 10.4.6 software CD a message states that a newer MacOs version is detected and that I will lose all data on the drive if I wish to install. Can't I re-install 10.4.6 withou

  • Restore from iCloud backup hangs on iOS7

    Hey, I updated my phone to iOS 7 yesterday and was stuck with the problem that neither music app nor podcasts and many other things (iTunes sync, spotlight search , etc were not working). One of the suggested fixes were to delete everything from the