Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6148671
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Oracle

2011-08-22 16:14:31

在使用dbms_redefinition将普通表转换为分区表的时候,若转换过程中创建中间表的DDL太长,Oracle会截取掉部分DDL,这个问题在11.2.0.2版本已经修复,以下是在11.2.0.1下测试的。
测试如下:
测试Oracle版本:
  1. SQL> select * from v$version;

  2. BANNER
  3. --------------------------------------------------------------------------------

  4. Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
  5. PL/SQL Release 11.2.0.1.0 - Production
  6. CORE 11.2.0.1.0 Production
  7. TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
  8. NLSRTL Version 11.2.0.1.0 - Production
1.创建需要重定义的表
  1. create table TB_HXL_USER
  2. (
  3.   STATEDATE DATE not null,
  4.   USERNUMBER VARCHAR2(13) not null,
  5.   PROVCODE NUMBER not null,
  6.   REM1 VARCHAR2(100),
  7.   REM2 VARCHAR2(100) default 'A' not null,
  8.   REM3 VARCHAR2(100),
  9.   REM4 VARCHAR2(100),
  10.   REM5 VARCHAR2(100),
  11.   REM6 VARCHAR2(100),
  12.   REM7 VARCHAR2(100),
  13.   REM8 VARCHAR2(100),
  14.   REM9 VARCHAR2(100),
  15.   REM10 VARCHAR2(100),
  16.   CREATE_DATE DATE not null,
  17.   CREATE_BY NUMBER not null,
  18.   LAST_UPDATE_DATE DATE not null,
  19.   LAST_UPDATE_BY NUMBER not null
  20. );

  21. create unique index IDX_TB_HXL_USER_U1 on TB_HXL_USER (STATEDATE, USERNUMBER, PROVCODE)
  22. ;

2.创建中间表

中间表目前是33个分区

  1. -- Create table

  2. create table tb_hxl_user_mid
  3. (
  4.   STATEDATE DATE not null,
  5.   USERNUMBER VARCHAR2(13) not null,
  6.   PROVCODE NUMBER not null,
  7.   REM1 VARCHAR2(100),
  8.   REM2 VARCHAR2(100) default 'A' not null,
  9.   REM3 VARCHAR2(100),
  10.   REM4 VARCHAR2(100),
  11.   REM5 VARCHAR2(100),
  12.   REM6 VARCHAR2(100),
  13.   REM7 VARCHAR2(100),
  14.   REM8 VARCHAR2(100),
  15.   REM9 VARCHAR2(100),
  16.   REM10 VARCHAR2(100),
  17.   CREATE_DATE DATE not null,
  18.   CREATE_BY NUMBER not null,
  19.   LAST_UPDATE_DATE DATE not null,
  20.   LAST_UPDATE_BY NUMBER not null
  21. )
  22. PARTITION BY RANGE (STATEDATE) SUBPARTITION BY list (PROVCODE)
  23. SUBPARTITION TEMPLATE
  24.          (SUBPARTITION p_01 values(01),
  25.           SUBPARTITION p_02 values(02),
  26.           SUBPARTITION p_03 values(03),
  27.           SUBPARTITION p_04 values(04),
  28.           SUBPARTITION p_05 values(05),
  29.           SUBPARTITION p_06 values(06),
  30.           SUBPARTITION p_07 values(07),
  31.           SUBPARTITION p_08 values(08),
  32.           SUBPARTITION p_09 values(09),
  33.           SUBPARTITION p_10 values(10),
  34.           SUBPARTITION p_11 values(11),
  35.           SUBPARTITION p_12 values(12),
  36.           SUBPARTITION p_13 values(13),
  37.           SUBPARTITION p_14 values(14),
  38.           SUBPARTITION p_15 values(15),
  39.           SUBPARTITION p_16 values(16),
  40.           SUBPARTITION p_17 values(17),
  41.           SUBPARTITION p_18 values(18),
  42.           SUBPARTITION p_19 values(19),
  43.           SUBPARTITION p_20 values(20),
  44.           SUBPARTITION p_21 values(21),
  45.           SUBPARTITION p_22 values(22),
  46.           SUBPARTITION p_23 values(23),
  47.           SUBPARTITION p_24 values(24),
  48.           SUBPARTITION p_25 values(25),
  49.           SUBPARTITION p_26 values(26),
  50.           SUBPARTITION p_27 values(27),
  51.           SUBPARTITION p_28 values(28),
  52.           SUBPARTITION p_29 values(29),
  53.           SUBPARTITION p_30 values(30)
  54.          )
  55.    (PARTITION p_20110515 VALUES LESS THAN (to_date('20110516','YYYYMMDD'))
  56.     );

  57. -- Create/Recreate indexes

  58. create unique index IDX_TB_HXL_USER_MID_U1
  59. on TB_HXL_USER_MID (STATEDATE, USERNUMBER, PROVCODE) local;

  60. alter table TB_HXL_USER_MID add partition p_20110516 VALUES LESS THAN (to_date('20110517','YYYYMMDD'));
  61. alter table TB_HXL_USER_MID add partition p_20110517 VALUES LESS THAN (to_date('20110518','YYYYMMDD'));
  62. alter table TB_HXL_USER_MID add partition p_20110518 VALUES LESS THAN (to_date('20110519','YYYYMMDD'));
  63. alter table TB_HXL_USER_MID add partition p_20110519 VALUES LESS THAN (to_date('20110520','YYYYMMDD'));
  64. alter table TB_HXL_USER_MID add partition p_20110520 VALUES LESS THAN (to_date('20110521','YYYYMMDD'));
  65. alter table TB_HXL_USER_MID add partition p_20110521 VALUES LESS THAN (to_date('20110522','YYYYMMDD'));
  66. alter table TB_HXL_USER_MID add partition p_20110522 VALUES LESS THAN (to_date('20110523','YYYYMMDD'));
  67. alter table TB_HXL_USER_MID add partition p_20110523 VALUES LESS THAN (to_date('20110524','YYYYMMDD'));
  68. alter table TB_HXL_USER_MID add partition p_20110524 VALUES LESS THAN (to_date('20110525','YYYYMMDD'));
  69. alter table TB_HXL_USER_MID add partition p_20110525 VALUES LESS THAN (to_date('20110526','YYYYMMDD'));
  70. alter table TB_HXL_USER_MID add partition p_20110526 VALUES LESS THAN (to_date('20110527','YYYYMMDD'));
  71. alter table TB_HXL_USER_MID add partition p_20110527 VALUES LESS THAN (to_date('20110528','YYYYMMDD'));
  72. alter table TB_HXL_USER_MID add partition p_20110528 VALUES LESS THAN (to_date('20110529','YYYYMMDD'));
  73. alter table TB_HXL_USER_MID add partition p_20110529 VALUES LESS THAN (to_date('20110530','YYYYMMDD'));
  74. alter table TB_HXL_USER_MID add partition p_20110530 VALUES LESS THAN (to_date('20110531','YYYYMMDD'));
  75. alter table TB_HXL_USER_MID add partition p_20110531 VALUES LESS THAN (to_date('20110601','YYYYMMDD'));
  76. alter table TB_HXL_USER_MID add partition p_20110601 VALUES LESS THAN (to_date('20110602','YYYYMMDD'));
  77. alter table TB_HXL_USER_MID add partition p_20110602 VALUES LESS THAN (to_date('20110603','YYYYMMDD'));
  78. alter table TB_HXL_USER_MID add partition p_20110603 VALUES LESS THAN (to_date('20110604','YYYYMMDD'));
  79. alter table TB_HXL_USER_MID add partition p_20110604 VALUES LESS THAN (to_date('20110605','YYYYMMDD'));
  80. alter table TB_HXL_USER_MID add partition p_20110605 VALUES LESS THAN (to_date('20110606','YYYYMMDD'));
  81. alter table TB_HXL_USER_MID add partition p_20110606 VALUES LESS THAN (to_date('20110607','YYYYMMDD'));
  82. alter table TB_HXL_USER_MID add partition p_20110607 VALUES LESS THAN (to_date('20110608','YYYYMMDD'));
  83. alter table TB_HXL_USER_MID add partition p_20110608 VALUES LESS THAN (to_date('20110609','YYYYMMDD'));
  84. alter table TB_HXL_USER_MID add partition p_20110609 VALUES LESS THAN (to_date('20110610','YYYYMMDD'));
  85. alter table TB_HXL_USER_MID add partition p_20110610 VALUES LESS THAN (to_date('20110611','YYYYMMDD'));
  86. alter table TB_HXL_USER_MID add partition p_20110611 VALUES LESS THAN (to_date('20110612','YYYYMMDD'));
  87. alter table TB_HXL_USER_MID add partition p_20110612 VALUES LESS THAN (to_date('20110613','YYYYMMDD'));
  88. alter table TB_HXL_USER_MID add partition p_20110613 VALUES LESS THAN (to_date('20110614','YYYYMMDD'));
  89. alter table TB_HXL_USER_MID add partition p_20110614 VALUES LESS THAN (to_date('20110615','YYYYMMDD'));
  90. alter table TB_HXL_USER_MID add partition p_20110615 VALUES LESS THAN (to_date('20110616','YYYYMMDD'));
  91. alter table TB_HXL_USER_MID add partition p_20110616 VALUES LESS THAN (to_date('20110617','YYYYMMDD'));

3.执行重定义

  1. SQL> Begin
  2.   2 dbms_redefinition.can_redef_table(uname => 'HXL',
  3.   3 tname =>'TB_HXL_USER',
  4.   4 options_flag => dbms_redefinition.cons_use_rowid);
  5.   5 End;
  6.   6 /

  7. PL/SQL procedure successfully completed.

  8. SQL> Begin
  9.   2 dbms_redefinition.start_redef_table(uname =>'HXL' ,
  10.   3 orig_table => 'TB_HXL_USER',
  11.   4 int_table => 'TB_HXL_USER_MID',
  12.   5 options_flag => dbms_redefinition.cons_use_rowid
  13.   6 );
  14.   7 End;
  15.   8 /

  16. PL/SQL procedure successfully completed.

4.中断重定义后

步骤3执行成功,说明目前该表能执行重定义,现在中断重定义,在中间表新增分区后再重定义。

  1. SQL> Begin
  2.   2 dbms_redefinition.abort_redef_table(uname =>'HXL'
  3.   3 ,orig_table => 'TB_HXL_USER'
  4.   4 ,int_table => 'TB_HXL_USER_MID'
  5.   5 );
  6.   6 End;
  7.   
  8. PL/SQL procedure successfully completed.

新增14个分区

  1. alter table TB_HXL_USER_MID add partition p_20110617 VALUES LESS THAN (to_date('20110618','YYYYMMDD'));
  2. alter table TB_HXL_USER_MID add partition p_20110618 VALUES LESS THAN (to_date('20110619','YYYYMMDD'));
  3. alter table TB_HXL_USER_MID add partition p_20110619 VALUES LESS THAN (to_date('20110620','YYYYMMDD'));
  4. alter table TB_HXL_USER_MID add partition p_20110620 VALUES LESS THAN (to_date('20110621','YYYYMMDD'));
  5. alter table TB_HXL_USER_MID add partition p_20110621 VALUES LESS THAN (to_date('20110622','YYYYMMDD'));
  6. alter table TB_HXL_USER_MID add partition p_20110622 VALUES LESS THAN (to_date('20110623','YYYYMMDD'));
  7. alter table TB_HXL_USER_MID add partition p_20110623 VALUES LESS THAN (to_date('20110624','YYYYMMDD'));
  8. alter table TB_HXL_USER_MID add partition p_20110624 VALUES LESS THAN (to_date('20110625','YYYYMMDD'));
  9. alter table TB_HXL_USER_MID add partition p_20110625 VALUES LESS THAN (to_date('20110626','YYYYMMDD'));
  10. alter table TB_HXL_USER_MID add partition p_20110626 VALUES LESS THAN (to_date('20110627','YYYYMMDD'));
  11. alter table TB_HXL_USER_MID add partition p_20110627 VALUES LESS THAN (to_date('20110628','YYYYMMDD'));
  12. alter table TB_HXL_USER_MID add partition p_20110628 VALUES LESS THAN (to_date('20110629','YYYYMMDD'));
  13. alter table TB_HXL_USER_MID add partition p_20110629 VALUES LESS THAN (to_date('20110630','YYYYMMDD'));
  14. alter table TB_HXL_USER_MID add partition p_20110630 VALUES LESS THAN (to_date('20110701','YYYYMMDD'));

5.新增分区后再次重定义

这个时候过程抛出了异常,这个是因为创建中间表的DDL的SQL太长了,oracle截掉了一部分后导致的。该问题在11.2.0.2.上已经修复。

  1. SQL> Begin
  2.   2 dbms_redefinition.can_redef_table(uname => 'HXL',
  3.   3 tname =>'TB_HXL_USER',
  4.   4 options_flag => dbms_redefinition.cons_use_rowid);
  5.   5 End;
  6.   6 /

  7. PL/SQL procedure successfully completed.

  8. SQL> Begin
  9.   2 dbms_redefinition.start_redef_table(uname =>'HXL' ,
  10.   3 orig_table => 'TB_HXL_USER',
  11.   4 int_table => 'TB_HXL_USER_MID',
  12.   5 options_flag => dbms_redefinition.cons_use_rowid
  13.   6 );
  14.   7 End;
  15.   8 /
  16. Begin
  17. *
  18. ERROR at line 1:
  19. ORA-00907: missing right parenthesis
  20. ORA-06512: at "SYS.DBMS_REDEFINITION", line 52
  21. ORA-06512: at "SYS.DBMS_REDEFINITION", line 1646
  22. ORA-06512: at line 2

 

 

 

阅读(2966) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~