ORA-14758: Last partition in the range section cannot be dropped

dcswinner發表於2012-09-22

今天發現oracle11g中用oracle自動建立分割槽的新功能後,刪除舊分割槽報ORA-14758: Last partition in the range section cannot be dropped錯誤。

oracle對此錯誤的解釋是:

ORA-14758: Last partition in the range section cannot be dropped
Cause: An attempt was made to drop the last range partition of an interval partitioned table.
Action: Do not attempt to drop this partition.

實驗如下:

1.建立自動分割槽的表:

SQL> create table TB_DYNA_TABLE
(
  NUM                        NUMBER,
  NAME                       VARCHAR2(30),
  CRT_TIME                   DATE not null
)
partition by range (CRT_TIME)
interval(numtodsinterval(1,'DAY'))
(PARTITION P20120919 VALUES LESS THAN (TO_DATE(' 2012-09-20 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')));
根據建立時間按天建立分割槽表。

插入幾條資料:

SQL>
SQL> INSERT INTO TB_DYNA_TABLE(NUM,NAME,CRT_TIME)
  2  VALUES(1,'DONGCS1',TO_DATE('2012-09-15','YYYY-MM-DD'));
 
1 row inserted
SQL> INSERT INTO TB_DYNA_TABLE(NUM,NAME,CRT_TIME)
  2  VALUES(2,'DONGCS2',TO_DATE('2012-09-20','YYYY-MM-DD'));
 
1 row inserted
SQL> INSERT INTO TB_DYNA_TABLE(NUM,NAME,CRT_TIME)
  2  VALUES(3,'DONGCS3',TO_DATE('2012-09-21','YYYY-MM-DD'));
 
1 row inserted
SQL> INSERT INTO TB_DYNA_TABLE(NUM,NAME,CRT_TIME)
  2  VALUES(4,'DONGCS4',TO_DATE('2012-09-22','YYYY-MM-DD'));
 
1 row inserted
SQL> INSERT INTO TB_DYNA_TABLE(NUM,NAME,CRT_TIME)
  2  VALUES(5,'DONGCS5',TO_DATE('2012-09-23','YYYY-MM-DD'));
 
1 row inserted
SQL> INSERT INTO TB_DYNA_TABLE(NUM,NAME,CRT_TIME)
  2  VALUES(6,'DONGCS6',TO_DATE('2012-09-24','YYYY-MM-DD'));
 
1 row inserted
 
SQL> commit;
 
Commit complete

查詢資料情況:

SQL> select * from TB_DYNA_TABLE;
 
       NUM NAME                           CRT_TIME
---------- ------------------------------ -----------
         1 DONGCS1                        2012-9-15
         2 DONGCS2                        2012-9-20
         3 DONGCS3                        2012-9-21
         4 DONGCS4                        2012-9-22
         5 DONGCS5                        2012-9-23
         6 DONGCS6                        2012-9-24
 
6 rows selected

查詢表的分割槽資訊:

SQL> SELECT t.table_name,t.partition_name,t.partition_position FROM User_Tab_Partitions t WHERE t.table_name='TB_DYNA_TABLE';
 
TABLE_NAME                     PARTITION_NAME                 PARTITION_POSITION
------------------------------ ------------------------------ ------------------
TB_DYNA_TABLE                  P20120919                                       1
TB_DYNA_TABLE                  SYS_P61                                         2
TB_DYNA_TABLE                  SYS_P63                                         3
TB_DYNA_TABLE                  SYS_P62                                         4
TB_DYNA_TABLE                  SYS_P65                                         5
TB_DYNA_TABLE                  SYS_P64                                         6
 
6 rows selected

刪除第一個分割槽看看:

SQL> alter table TB_DYNA_TABLE drop partition P20120919;
 
alter table TB_DYNA_TABLE drop partition P20120919
 
ORA-14758: Last partition in the range section cannot be dropped

看來第一個分割槽刪不了。
 刪除其他分割槽看看:

SQL>  alter table TB_DYNA_TABLE drop partition SYS_P61;
 
Table altered
 
SQL> alter table TB_DYNA_TABLE drop partition SYS_P63;
 
Table altered

其他分割槽可以刪除。

查詢表的分割槽資訊:

SQL> SELECT t.table_name,t.partition_name,t.partition_position FROM User_Tab_Partitions t WHERE t.table_name='TB_DYNA_TABLE';
 
TABLE_NAME                     PARTITION_NAME                 PARTITION_POSITION
------------------------------ ------------------------------ ------------------
TB_DYNA_TABLE                  P20120919                                       1
TB_DYNA_TABLE                  SYS_P62                                         2
TB_DYNA_TABLE                  SYS_P65                                         3
TB_DYNA_TABLE                  SYS_P64                                         4
總結:

1.建表時需要指定第一個初始化的分割槽

2.插入資料後,分割槽根據插入的資料自動分割槽了;

3.刪除第一個分割槽刪除不了,只能刪除之後的分割槽。

另外還需注意:如果表有索引且不是分割槽索引,刪除分割槽後(分割槽裡面且有資料),那麼需要重建索引。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12129601/viewspace-744832/,如需轉載,請註明出處,否則將追究法律責任。

相關文章