ORA-30078報錯的兩種解決方案

Hoegh發表於2016-07-12
    最近在嘗試建立分割槽表時遇到了ORA-30078報錯,提示“ORA-30078: 分割槽界限必須是 TIME/TIMESTAMP WITH TIME ZONE 文字”,很納悶兒為什麼會報錯。
   首先我建立一個測試表hoegh1,其中包含一個date型別的時間欄位,並以該欄位做範圍分割槽,建立成功;
   緊接著,嘗試建立測試表hoegh2,其中包含一個timestamp型別的時間欄位,並以該欄位做範圍分割槽,建立失敗,遇到了ORA-30078報錯
   過程如下:
點選(此處)摺疊或開啟
  1. SQL>
  2. SQL> select * from v$version;

  3. BANNER
  4. ----------------------------------------------------------------
  5. Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
  6. PL/SQL Release 10.2.0.4.0 - Production
  7. CORE 10.2.0.4.0 Production
  8. TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
  9. NLSRTL Version 10.2.0.4.0 - Production

  10. SQL>
  11. SQL>
  12. SQL> create table hoegh1
  13.   2 (
  14.   3 id NUMBER,
  15.   4 time date
  16.   5 )
  17.   6 partition by range(time)
  18.   7 (
  19.   8 partition p_201505 values less than(to_date('20150601','yyyymmdd')),
  20.   9 partition p_201506 values less than(to_date('20150701','yyyymmdd')),
  21.  10 partition p_201507 values less than(to_date('20150801','yyyymmdd')),
  22.  11 partition p_201508 values less than(to_date('20150901','yyyymmdd')),
  23.  12 partition p_201509 values less than(to_date('20151001','yyyymmdd')),
  24.  13 partition p_201510 values less than(to_date('20151101','yyyymmdd')),
  25.  14 partition p_201511 values less than(to_date('20151201','yyyymmdd')),
  26.  15 partition p_201512 values less than(to_date('20160101','yyyymmdd')),
  27.  16 partition p_201601 values less than(to_date('20160201','yyyymmdd')),
  28.  17 partition p_201602 values less than(to_date('20160301','yyyymmdd')),
  29.  18 partition p_201603 values less than(to_date('20160401','yyyymmdd')),
  30.  19 partition p_201604 values less than(to_date('20160501','yyyymmdd')),
  31.  20 partition p_201605 values less than(to_date('20160601','yyyymmdd')),
  32.  21 partition p_201606 values less than(to_date('20160701','yyyymmdd')),
  33.  22 partition p_201607 values less than(to_date('20160801','yyyymmdd'))
  34.  23 );

  35. 表已建立。

  36. SQL>
  37. SQL>
  38. SQL> create table hoegh2
  39.   2 (
  40.   3 id NUMBER,
  41.   4 TIMESTAMP TIMESTAMP(6)
  42.   5 )
  43.   6 partition by range(TIMESTAMP)
  44.   7 (
  45.   8 partition p_201505 values less than(to_timestamp('20150601','yyyymmdd')),
  46.   9 partition p_201506 values less than(to_timestamp('20150701','yyyymmdd')),
  47.  10 partition p_201507 values less than(to_timestamp('20150801','yyyymmdd')),
  48.  11 partition p_201508 values less than(to_timestamp('20150901','yyyymmdd')),
  49.  12 partition p_201509 values less than(to_timestamp('20151001','yyyymmdd')),
  50.  13 partition p_201510 values less than(to_timestamp('20151101','yyyymmdd')),
  51.  14 partition p_201511 values less than(to_timestamp('20151201','yyyymmdd')),
  52.  15 partition p_201512 values less than(to_timestamp('20160101','yyyymmdd')),
  53.  16 partition p_201601 values less than(to_timestamp('20160201','yyyymmdd')),
  54.  17 partition p_201602 values less than(to_timestamp('20160301','yyyymmdd')),
  55.  18 partition p_201603 values less than(to_timestamp('20160401','yyyymmdd')),
  56.  19 partition p_201604 values less than(to_timestamp('20160501','yyyymmdd')),
  57.  20 partition p_201605 values less than(to_timestamp('20160601','yyyymmdd')),
  58.  21 partition p_201606 values less than(to_timestamp('20160701','yyyymmdd')),
  59.  22 partition p_201607 values less than(to_timestamp('20160801','yyyymmdd'))
  60.  23 );
  61.   partition p_201505 values less than(to_timestamp('20150601','yyyymmdd')),
  62.                                       *
  63. 第 8 行出現錯誤:
  64. ORA-30078: 分割槽界限必須是 TIME/TIMESTAMP WITH TIME ZONE 文字


  65. SQL>
    鑑於timestamp型別的時間精度比date型別的要高,因此不能修改列的型別。那怎麼辦呢?在這兒列出兩種解決方案。

一、PARTITION value 型別更改為to_date('20150601','yyyymmdd')

點選(此處)摺疊或開啟
  1. SQL>
  2. SQL> create table hoegh2
  3.   2 (
  4.   3 id NUMBER,
  5.   4 TIMESTAMP TIMESTAMP(6)
  6.   5 )
  7.   6 partition by range(TIMESTAMP)
  8.   7 (
  9.   8 partition p_201505 values less than(to_date('20150601','yyyymmdd')),
  10.   9 partition p_201506 values less than(to_date('20150701','yyyymmdd')),
  11.  10 partition p_201507 values less than(to_date('20150801','yyyymmdd')),
  12.  11 partition p_201508 values less than(to_date('20150901','yyyymmdd')),
  13.  12 partition p_201509 values less than(to_date('20151001','yyyymmdd')),
  14.  13 partition p_201510 values less than(to_date('20151101','yyyymmdd')),
  15.  14 partition p_201511 values less than(to_date('20151201','yyyymmdd')),
  16.  15 partition p_201512 values less than(to_date('20160101','yyyymmdd')),
  17.  16 partition p_201601 values less than(to_date('20160201','yyyymmdd')),
  18.  17 partition p_201602 values less than(to_date('20160301','yyyymmdd')),
  19.  18 partition p_201603 values less than(to_date('20160401','yyyymmdd')),
  20.  19 partition p_201604 values less than(to_date('20160501','yyyymmdd')),
  21.  20 partition p_201605 values less than(to_date('20160601','yyyymmdd')),
  22.  21 partition p_201606 values less than(to_date('20160701','yyyymmdd')),
  23.  22 partition p_201607 values less than(to_date('20160801','yyyymmdd'))
  24.  23 );

  25. 表已建立。

  26. SQL>

二、PARTITION value 型別更改timestamp'2015-06-01 00:00:00.000000'
點選(此處)摺疊或開啟

  1. SQL>
  2. SQL> drop table hoegh2 purge;

  3. 表已刪除。

  4. SQL> create table hoegh2
  5.   2 (
  6.   3 id NUMBER,
  7.   4 TIMESTAMP TIMESTAMP(6)
  8.   5 )
  9.   6 partition by range(TIMESTAMP)
  10.   7 (
  11.   8 partition p_201505 values less than(timestamp'2015-06-01 00:00:00.000000'),
  12.   9 partition p_201506 values less than(timestamp'2015-07-01 00:00:00.000000'),
  13.  10 partition p_201507 values less than(timestamp'2015-08-01 00:00:00.000000'),
  14.  11 partition p_201508 values less than(timestamp'2015-09-01 00:00:00.000000'),
  15.  12 partition p_201509 values less than(timestamp'2015-10-01 00:00:00.000000'),
  16.  13 partition p_201510 values less than(timestamp'2015-11-01 00:00:00.000000'),
  17.  14 partition p_201511 values less than(timestamp'2015-12-01 00:00:00.000000'),
  18.  15 partition p_201512 values less than(timestamp'2016-01-01 00:00:00.000000'),
  19.  16 partition p_201601 values less than(timestamp'2016-02-01 00:00:00.000000'),
  20.  17 partition p_201602 values less than(timestamp'2016-03-01 00:00:00.000000'),
  21.  18 partition p_201603 values less than(timestamp'2016-04-01 00:00:00.000000'),
  22.  19 partition p_201604 values less than(timestamp'2016-05-01 00:00:00.000000'),
  23.  20 partition p_201605 values less than(timestamp'2016-06-01 00:00:00.000000'),
  24.  21 partition p_201606 values less than(timestamp'2016-07-01 00:00:00.000000'),
  25.  22 partition p_201607 values less than(timestamp'2016-08-01 00:00:00.000000')
  26.  23 );

  27. 表已建立。

  28. SQL>

   雖然問題得到了順利解決,但是為什麼會報錯還是沒弄明白,如果有了解原理的朋友還望不吝賜教。



~~~~~~~ the end~~~~~~~~~
hoegh
2016.07.12

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

相關文章