<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

    常用鏈接

    統計

    IT技術鏈接

    保險相關

    友情鏈接

    基金知識

    生活相關

    最新評論

    普通表轉分區表和交換分區(oracle)

    將普通表轉換成分區表有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';  

      

    --方法二 交換分區   

         這種方法只是對數據字典中分區和表的定義進行了修改,沒有數據的修改或復制,效率最高。適用于包含大數據量的表轉到分區表中的一個分區的操作。盡量在閑時進行操作。  

      

    交換分區的操作步驟如下:  

         1. 創建分區表,假設有2個分區,P1,P2.  

         2. 創建表A存放P1規則的數據。  

         3. 創建表B 存放P2規則的數據。  

         4. 用表A 和P1 分區交換。 把表A的數據放到到P1分區  

         5. 用表B 和p2 分區交換。 把表B的數據存放到P2分區。  

      

      

      

    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一條數據,t_phone_test_0里4410條數據,交換之后p0是4410,t_phone_test_0是1,再執行一次數據又換回來了。   

      

    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';  

      

      

    --合并分區   

    ----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;  

      

    --此時p0中有p0和p10的數據,但是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.創建分區表  

    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.創建基表  

    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.添加分區  

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

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

    4.交換分區  

    alter table t_phone_test exchange partition p10 with table t_phone_test_10;     

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

    5.合并分區  

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

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

    --此時p0中有p0和p10的數據,但是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.交換分區  

    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.刪除分區 和添加分區  

    alter table t_phone_test  drop partition p0;  

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

      

    7.篩選數據  

    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.交換分區  

    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 鴻雁 閱讀(322) 評論(0)  編輯  收藏 所屬分類: 數據庫

    主站蜘蛛池模板: 亚洲AV天天做在线观看| 亚洲精品乱码久久久久久蜜桃不卡 | 亚洲AV成人一区二区三区AV| 国产大片免费天天看| 久久久久亚洲AV综合波多野结衣| 美女被免费视频网站a| 亚洲成年人啊啊aa在线观看| MM1313亚洲精品无码久久| 免费夜色污私人影院在线观看| WWW亚洲色大成网络.COM| 亚洲第一页综合图片自拍| 日韩a毛片免费观看| 国产AⅤ无码专区亚洲AV| 97在线视频免费公开视频| 久久亚洲精品成人综合| 亚洲美女视频免费| 性xxxx黑人与亚洲| 波多野结衣久久高清免费 | 亚洲Aⅴ在线无码播放毛片一线天| 四虎www免费人成| 羞羞视频在线免费观看| 亚洲人成影院在线无码按摩店| 精品国产麻豆免费人成网站| 亚洲电影唐人社一区二区| 国产精品成人免费一区二区| 国产综合成人亚洲区| 国产亚洲精品激情都市| 日本免费大黄在线观看| 亚洲欧洲AV无码专区| 亚洲高清最新av网站| 最近免费中文字幕MV在线视频3| 色播亚洲视频在线观看| 免费无码一区二区三区蜜桃大 | 国产亚洲综合一区二区三区| 亚洲精品国产精品乱码在线观看| 69视频在线观看高清免费| 亚洲欧美日韩自偷自拍| 亚洲综合色自拍一区| 成人女人A级毛片免费软件| 真正全免费视频a毛片| 老司机亚洲精品影院无码|