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

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

  • Partition exchange doumentation problems

    Oracle 10gR2 EE / Aix5L
    I have a partitioned table on which the primary key is DISABLE VALIDATE and want to exchange a single table with a partition.
    I did that because documentation "UNIQUE Constraints in a Data Warehouse" says :
    "However, there are trade-offs for the data warehouse administrator to consider with DISABLE VALIDATE constraints. Because this constraint is disabled, no DML statements that modify the unique column are permitted against the sales table. You can use one of two strategies for modifying this table in the presence of a constraint:
    * Use DDL to add data to this table (such as exchanging partitions)..."
    Problem #1 :
    "Because this constraint is disabled, no DML statements that modify the unique column are permitted against the sales table."
    That sentence lets suppose that DELETEs or UPDATEs (columns different from PK) should be permitted cause they won't break the uniqueness. That's false. In fact, no DML statements at all are permitted.
    Problem #2 : It's impossible to exchange a single table with a partition when PK is disable Validate (ORA-25132 : UNIQUE constraint (string.string) disabled and validated in ALTER TABLE EXCHANGE PARTITION
    Cause: cannot ALTER TABLE EXCHANGE PARTITION when the partition and the table have a disabled and validated unique constraints AND the unique keys in the partion is not mutually exclusive from the rest of the table.)
    The only way to succeed is to NOValidate the PK, exchange the table and the partition, and Validate the PK. I precise that "Validate PK" succeeds and means that "the unique keys in the partion IS mutually exclusive from the rest of the table."
    Some explanations or advices...
    Thanks for reading my message.

    jpsql wrote:
    For those interested.
    Yes, it is possible to exchange a single table with a partition. The PK of the single table was not VALIDATE. The PK of the partitioned table and the one of the single table have to be both DISBABLED and VALIDATED.Could you elaborate a bit on this? What was exactly the difference to your initial setup? I think I understand that the PK of your unpartitioned table was initially NOT VALIDATED (status ENABLED/DISABLED?) whereas the PK on your partitioned table was VALIDATED, but DISABLED. Now you've VALIDATED the PK of your unpartitioned table (and DISABLED it?) and then you were able to perform the exchange partition without an error message?
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • 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

  • 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

  • After creating partition, problems start

    I use Boot Camp Asst. and create a 32 GB partition. at the end of the process, I'm told to "hit the Restart key or hold the power key for a few seconds." Since i have no restart key on my MacBook, I hold down the power key. Then the system turns off. I turn it on again, and reboot. I get an error - osx shut down unexpectedly, do i want to report to apple. whatever. the space i allocated on the partition is gone from my free space, but if I go into BCA, it doesn't seem to know that i've already created a partition. things are screwy and i have to reboot from the Leopard disk and use Disk Utility to repair the disk.
    So, how do I get around this? I really want to use boot camp.

    I have it all fixed (except that the Windows XP system won't completely shut down or restart into any startup volume...I have to hold down the power button until shutdown, then start by pressing the start button).
    AppleCare tech, on two different calls, spoke of a bug in OS X (10.5.2) that is causing the partition problem described by me and others in this thread.
    The solution (assuming that you don't have a Windows partition yet) is to install OS X (10.5.1). Don't do any software updates to 10.5.1 until you've completed the Windows install using Boot Camp Assistant.
    Remember to have backups.
    I didn't exactly follow the solution directly. I reinstalled Tiger 10.4.11. Then I installed 10.5.1 as an upgrade. The reason for this is that I was not warned by AppleCare tech that a 10.5.2 install using "erase and install" would delete the entire iLife '06 suite. I lost iLife '06. That's why I reverted to Tiger before attempting the Leopard and Boot Camp installations.

  • Outlook connection to exchange server problem

    We have a new domain and an existing exchange server. The problem is if i log in with a local computer account i can autodiscover and connect in cached mode to exchange no problem. If i then login with a domain user account the same computer (tried on other
    workstations) will fail to auto discover, fail to connect to exchange even with manual settings. I cant find anything obvious in Group policy.
    The server is setup with the latest 2013 Group policy templates with office 2013 templates
    Users not logged in with the new AD server can connect to exchange 
    Users not logged into the domain can access exchange server
    My feeling is its a local setting that is missing or needs to be changed in Group Policy but i am at a loss as to what it could be
    I have disabled roaming profiles too and it makes no difference.
    Any help would be greatly appreciated.
    Steve

    Hi,
    Sorry for my delay. According to your description, I summarize your issue to the following points:
    1. No problem when the user logs in Outlook with a local computer account in Cached mode.
    2. Can’t connect to Exchange from an cache mode enabled Outlook 2013 client when using a domain user account on the same computer automatically or manually.
    3. Can connect to Exchange from an online mode enabled Outlook 2013 client when using a domain user account on the same computer automatically or manually.
    It is right? If I misunderstand, please feel free to point it out. Additionally, I noticed that the server is setup with the latest 2013 Group policy templates with office 2013 templates. Please confirm
    if the Outlook cache mode is disabled by OTC or GPO. If there is following registry key applied on the machine:
    Software\Microsoft\Office\15.0\Outlook\Cached Mode
    Meanwhile, please try to install an Outlook 2013 with a fresh ISO file(Don’t use any template such as OCT template), see if the Cached mode Outlook can connect to Exchange server.
    Waiting for your updates.
    Regards,
    Winnie Liang
    TechNet Community Support

  • 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

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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.

  • 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.

  • 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.

  • Exchange Partition Usage

    Hi,
    We store data from the main table by referring other lookup tables and store them temporarily in a Swap table and then
    in the end, we move data from here to the Main table using Exchange Partition.
    EXECUTE IMMEDIATE('ALTER TABLE TMP_SWAP EXCHANGE PARTITION PRT_TMP_SWAP WITH TABLE MAIN_TABLE');
    It is equivalent to Truncating data in the main table and insert data into it by reading from the swap table.
    Please tell me, how internally oracle handles "EXCHANGE PARTITION" implementation and how we get better performance
    instead of using TRUNCATE and INSERT, thank you.
    Regards,
    Deva

    Hi,
    It simply detaches extents/data blocks from the source table and attaches it to the destination table.
    This is the reason performance is better than INSERT statement.
    Regards
    Message was edited by:
    Citrus
    corrected a typo

  • High wait on Library Cache Lock while doing ALTER TABLE EXCHANGE PARTITION

    We are observing a very high wait time on "Library cache lock" while performing Exchange partition.
    Here we go
    ALTER TABLE PSALESREG EXCHANGE PARTITION P123
    WITH TABLE PBKPSALESREF WITHOUT VALIDATION
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.11 *6684.73* 2 9 2 0
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.11 6684.73 2 9 2 0
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Elapsed times include waiting on following events:
    Event waited on Times Max. Wait Total Waited
    ---------------------------------------- Waited ---------- ------------
    library cache lock 2274 3.12 *6681.32*
    Is it a bug? is anyone there who experienced the same issue?
    Rgds

    Maurice Muller wrote:
    Hi,
    As far as I remember a exchange partition can only be done when no other query is accessing the table.
    So you should check if any other queries are executed against the table PSALESREG while you do the exchange partition. Maurice,
    queries won't block the exchange operation but continue to read from the "original", exchanged segment; this "cross-DDL" read consistency is a feature that has been introduced a long time ago.
    But any kind of (long-running) DML should effectively prevent the exchange operation. Still I would assume that this shouldn't show up as "library cache lock", but you would get an "ORA-00054: resource busy" error.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

Maybe you are looking for

  • My mac turns off when the battery reach full charge, what's wrong?

    It was working all right, but after a trip, the Mac didn't start, when i try to start the mac only with the battery, Started normally, i worked that way for a few moments, then i start to charge the battery, a soon the battery reached full charge the

  • OSB cluster howto

    Can anyone cite documentation - formal, anecdotal, on stone tablets even - that explains how to set up OSB in a clustered configuration? We've been beating our heads against this for WAY too long. Oracle's documentation is...how shall I put this...in

  • Concurrent employment in SRM 4.0 with HR integration

    Hello all, SRM 4.0, HR 4.7 Just wandering about procedure how to solve concurrent employment (one user on several positions) in SRM 4.0 where this is not possible. Note 850328 is active and even in HR exist user on several position, SRM is taking onl

  • M2T Files in FCP

    I'm currently editing on FCP 7. I just downloaded a plugin from Sony that should allow me to use M2T files. I have a friend who has downloaded all of the files onto an external drive using his PC. Will I be able to copy the M2T files over onto my com

  • Create RSS

    hello I am focusing on creating a RSS file to be pointed by URL on a page . After a search on the web I found that managing RSS with java meaning to use ROME api. Is true? or does exist other api/project? If someone is using ROME api , can help m,e t