oracle创建分区

oracle提供了以下几种分区类型:

  1. 范围分区(range)--本篇本章讲解的分区

  2. 哈希分区(hash)

  3. 列表分区(list)

  4. 范围-哈希复合分区(range-hash)

  5. 范围-列表复合分区(range-list)

    查看分区数 :select*from user_tab_partitions where table_name='表名'
    查看分区内容:select * from 表名 partition(分区名) ;

    alter table 表名 add partition 分区名 values (分区字段)
    tablespace tbs_zba_czc --表空间
    pctfree 10 --预留的空间大小,10%
    initrans 1 --的是一个 block 上初始预分配给并行交易控制的空间
    maxtrans 255 --如果initrans 不够了,自动扩展,最大这个值

分区示例:

  create table emp02(
    EMPNO number,
    ENAME varchar2(10),
    JOB varchar2(9),
    MGR number,
    HIREDATE date,
    SAL number(7,2),
    COMM number(7,2),
    DEPTNO number)
   partition by range (HIREDATE) --主分区
   (
      partition p1 values less than (to_date('2021-02-1', 'yyyy-mm-dd'))
      tablespace itheima
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        next 1M
        minextents 1
        maxextents unlimited
      ),
      partition p2 values less than (to_date('2021-03-1', 'yyyy-mm-dd'))
      tablespace itheima
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        next 1M
        minextents 1
        maxextents unlimited
      )
    );

添加分区

方式一

alter table test add partition P20180111 values less than (TIMESTAMP '2018-01-12 00:00:00')

方式二

alter table test add  partition P20180112 values less than (to_date('20180113 00:00:00','yyyymmdd hh24:mi:ss'));

总结

(1)若在创建日分区的时候使用的是精确到秒的timestamp类型,由于其值与date类型是一致的,因此oracle引擎会将其与date同等对待,但是最终的建分区语句使用的还是timestamp,即使你在添加分区时使用的是to_date,也即是说以最开始见分区时候的关键字(timestamp)为准;
(2)若在创建日分区的时候使用的是精确到毫秒的timestamp类型,由于timestamp ‘20180101 00:00:00.000’与timestamp ‘20180101 00:00:00’值是一样的因此,会将二者同等对待;但是在但是最终的建分区语句使用的还是”timestamp精确到秒”,即使你在添加分区时使用的是”timestamp精确到毫秒”,也即是说以最开始见分区时候的”timestamp精确到秒”为准;
posted @ 2020-12-16 18:18  Polar_shy  阅读(1515)  评论(0)    收藏  举报