<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    The important thing in life is to have a great aim , and the determination

    常用鏈接

    統(tǒng)計(jì)

    IT技術(shù)鏈接

    保險(xiǎn)相關(guān)

    友情鏈接

    基金知識(shí)

    生活相關(guān)

    最新評(píng)論

    普通表轉(zhuǎn)分區(qū)表和交換分區(qū)(oracle)

    將普通表轉(zhuǎn)換成分區(qū)表有4種方法:  

           1. Export/import method  

           2. Insert with a subquery method  

           3. Partition exchange method  

           4.
    DBMS_REDEFINITION           


        select
     * from t_user_info_test;  


        --方法一
      

        drop table t_phone_test purge;  

    create table t_phone_test(phone,part) nologging  partition by list(part)  

    (  

    partition p0 values('0'),  

    partition p1 values('1'),  

    partition p2 values('2'),  

    partition p3 values('3'),  

    partition p4 values('4'),  

    partition p5 values('5'),  

    partition p6 values('6'),  

    partition p7 values('7'),  

    partition p8 values('8'),  

    partition p9 values('9')  

    )   

    as   

    select user_mobile phone,substr(user_mobile,-1,1) part  

    from t_user_info_test;  

      

      

    select * from t_phone_test partition(p0);  

      

    select * from t_phone_test where part='0';  

      

    --方法二 交換分區(qū)   

         這種方法只是對(duì)數(shù)據(jù)字典中分區(qū)和表的定義進(jìn)行了修改,沒(méi)有數(shù)據(jù)的修改或復(fù)制,效率最高。適用于包含大數(shù)據(jù)量的表轉(zhuǎn)到分區(qū)表中的一個(gè)分區(qū)的操作。盡量在閑時(shí)進(jìn)行操作。  

      

    交換分區(qū)的操作步驟如下:  

         1. 創(chuàng)建分區(qū)表,假設(shè)有2個(gè)分區(qū),P1,P2.  

         2. 創(chuàng)建表A存放P1規(guī)則的數(shù)據(jù)。  

         3. 創(chuàng)建表B 存放P2規(guī)則的數(shù)據(jù)。  

         4. 用表A 和P1 分區(qū)交換。 把表A的數(shù)據(jù)放到到P1分區(qū)  

         5. 用表B 和p2 分區(qū)交換。 把表B的數(shù)據(jù)存放到P2分區(qū)。  

      

      

      

    create table t_phone_test_0 nologging  

    as   

    select user_mobile phone,substr(user_mobile,-1,1) part  

    from t_user_info_test where substr(user_mobile,-1,1)='0';  

      

    select count(*) from t_phone_test where part='0';  

    --4410   

    select count(*) from t_user_info_test where substr(user_mobile,-1,1)='0';  

    --4410   

      

    alter table t_phone_test exchange partition p0 with table t_phone_test_0;  

      

      

    delete from   t_phone_test_0;  

      

    select count(*) from t_phone_test where part='0';  

    select count(*) from t_phone_test_0;  

      

    insert into t_phone_test(phone,part) values('15267046070','0');  

      

    --p0一條數(shù)據(jù),t_phone_test_0里4410條數(shù)據(jù),交換之后p0是4410,t_phone_test_0是1,再執(zhí)行一次數(shù)據(jù)又換回來(lái)了。   

      

    insert into t_phone_test_0(phone,part) values('15267046070','1');  

    alter table t_phone_test exchange partition p0 with table t_phone_test_0;  

    delete from t_phone_test_0 where part='1';  

      

      

    --合并分區(qū)   

    ----alter table tbname merge partitions/subpartitions pt1,pt2 into partition/subpartition pt3;   

      

    alter table t_phone_test merge partitions p0,p1 into partition p0;  

      

      

    select count(*) from t_phone_test where part='0';  

    select count(*) from t_phone_test where part='1';  

      

    select count(*)  from t_phone_test partition(p0);  

    select count(*)  from t_phone_test partition(p1);  

      

      

      

     alter table t_phone_test  add partition p10 values(default);  

      

    insert into t_phone_test(phone,part) values('15267046010','10');  

    insert into t_phone_test(phone,part) values('15267046020','20');  

      

    select * from   

      

    --   

    alter table t_phone_test drop partition p10;  

     alter table t_phone_test  add partition p10 values'10');  

       

    alter table t_phone_test exchange partition p10 with table t_phone_test_10;  

    --ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION   

    alter table T_PHONE_TEST_10 modify PART VARCHAR2(2);  

    alter table t_phone_test merge partitions p0,p10 into partition p0;  

      

    --此時(shí)p0中有p0和p10的數(shù)據(jù),但是p0的list不再是0而是0和10   

      partition P0 values ('10''0')  

        tablespace APP_DATAN  

        pctfree 10  

        initrans 1  

        maxtrans 255  

        storage  

        (  

          initial 1M  

          next 1M  

          minextents 1  

          maxextents unlimited  

          pctincrease 0  

        ),  

          

    alter table t_phone_test exchange partition p0 with table t_phone_test_10;     

    alter table t_phone_test drop partition p0;  

    alter table t_phone_test  add partition p0 values'0');      

      

    alter table t_phone_test exchange partition p0 with table t_phone_test_10;     

      

      

    drop table t_phone_test_10 purge;  

    create table t_phone_test_10 nologging  

    as   

    select user_mobile phone,substr(user_mobile,-2,2) part  

    from t_user_info_test where substr(user_mobile,-2,2)='10';  

      

    drop table t_phone_test_0 purge;  

    create table t_phone_test_0 nologging   

    as  

    select  phone,substr(phone,-1,1) part  

    from t_phone_test_10;  

      

    alter table t_phone_test exchange partition p0 with table t_phone_test_0;  

      

      

    select * from t_phone_test_10;  

      

      

      

    select count(*)  from t_phone_test partition(p0);  

    select count(*)  from t_phone_test partition(p10);  

    select count(*) from t_phone_test_10;  

    select count(*) from t_phone_test_0;  

      

      

      

    select substr('123456',-1,1),substr('123456',-2,2),substr('123456',-3,2) from dual;  

      

      

    ---------------------------------------------------------   

    1.創(chuàng)建分區(qū)表  

    drop table t_phone_test purge;  

    create table t_phone_test(phone,part) nologging  partition by list(part)  

    (  

    partition p0 values('0'),  

    partition p1 values('1'),  

    partition p2 values('2'),  

    partition p3 values('3'),  

    partition p4 values('4'),  

    partition p5 values('5'),  

    partition p6 values('6'),  

    partition p7 values('7'),  

    partition p8 values('8'),  

    partition p9 values('9')  

    )   

    as   

    select user_mobile phone,substr(user_mobile,-1,1) part  

    from t_user_info_test;  

      

    select count(*)  from t_phone_test partition(p0);--4410   

    select count(*)  from t_phone_test partition(p10);  

    select count(*) from t_phone_test_10;  

    select count(*) from t_phone_test_0;  

      

    2.創(chuàng)建基表  

    drop table t_phone_test_10 purge;  

    create table t_phone_test_10 nologging  

    as  

    select  phone,substr(phone,-2,2) part  

    from t_phone_test where substr(phone,-2,2)='10';  

      

    select count(*) from t_phone_test_10;--406   

      

    --ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION   

    alter table T_PHONE_TEST_10 modify PART VARCHAR2(2);  

      

    3.添加分區(qū)  

    alter table t_phone_test  add partition p10 values'10');      

    select count(*)  from t_phone_test partition(p10);--0   

    4.交換分區(qū)  

    alter table t_phone_test exchange partition p10 with table t_phone_test_10;     

    select count(*)  from t_phone_test partition(p10);--406   

    5.合并分區(qū)  

    alter table t_phone_test merge partitions p0,p10 into partition p0;  

    select count(*)  from t_phone_test partition(p0);--4816   

    --此時(shí)p0中有p0和p10的數(shù)據(jù),但是p0的list不再是0而是0和10   

      partition P0 values ('10''0')  

        tablespace APP_DATAN  

        pctfree 10  

        initrans 1  

        maxtrans 255  

        storage  

        (  

          initial 1M  

          next 1M  

          minextents 1  

          maxextents unlimited  

          pctincrease 0  

        ),  

          

    6.交換分區(qū)  

    alter table t_phone_test exchange partition p0 with table t_phone_test_10;    

      

    select count(*)  from t_phone_test partition(p0);--0   

    select count(*) from t_phone_test_10;--4816   

      

      

    6.刪除分區(qū) 和添加分區(qū)  

    alter table t_phone_test  drop partition p0;  

    alter table t_phone_test  add partition p0 values('0');  

      

    7.篩選數(shù)據(jù)  

    drop table t_phone_test_0 purge;  

    create table t_phone_test_0 nologging  

    as  

    select  phone,substr(phone,-1,1) part  

    from t_phone_test_10 where substr(phone,-1,1)='0';  

      

    select count(*) from t_phone_test_0;--4816   

      

    8.交換分區(qū)  

    alter table t_phone_test exchange partition p0 with table t_phone_test_0;    

      

    select count(*)  from t_phone_test partition(p0);--4816   
    select count(*) from t_phone_test_0;--0  

    posted on 2014-05-07 22:31 鴻雁 閱讀(328) 評(píng)論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫(kù)

    主站蜘蛛池模板: 99久久免费国产精品热| 亚洲一区二区在线视频| 亚洲VA综合VA国产产VA中| 免费看a级黄色片| 无码少妇一区二区浪潮免费| 13一14周岁毛片免费| 8x网站免费入口在线观看| 50岁老女人的毛片免费观看| 性xxxx视频免费播放直播| 免费在线看污视频| 久久久99精品免费观看| 91久久精品国产免费一区| 4444www免费看| 欧美好看的免费电影在线观看| 永久免费av无码不卡在线观看| 毛片在线免费视频| 麻豆国产入口在线观看免费| 国产精品色午夜免费视频| 国产一精品一aⅴ一免费| 亚洲精品老司机在线观看| 亚洲成av人片在线观看天堂无码| 亚洲伊人成无码综合网| 国产AV无码专区亚洲AV手机麻豆| 亚洲av无码片在线播放| 久久精品国产亚洲AV高清热| 亚洲制服丝袜在线播放| 久久无码av亚洲精品色午夜| 黄色a级片免费看| 在线观看免费无码专区| 全部免费毛片在线播放| 亚洲免费综合色在线视频| 国产在线a不卡免费视频| 亚洲午夜福利精品久久| 亚洲成A人片在线观看WWW| 亚洲欧洲综合在线| 亚洲精品成a人在线观看夫| ww在线观视频免费观看w| 精品一区二区三区免费毛片爱| 免费无码又爽又刺激聊天APP| 国产又粗又猛又爽又黄的免费视频 | 亚洲神级电影国语版|