你好,游客 登录 注册 搜索
背景:
阅读新闻

ORA-30078报错的两种解决方案

[日期:2016-07-13] 来源:Linux社区  作者:Hoegh [字体: ]

最近在尝试创建分区表时遇到了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>

虽然问题得到了顺利解决,但是为什么会报错还是没弄明白,如果有了解原理的朋友还望不吝赐教。

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-07/133123.htm

linux
相关资讯       ORA-30078