zoukankan      html  css  js  c++  java
  • oracle数据库创建分区表

    参考资料:http://blog.chinaunix.net/uid-21943216-id-4062400.html

    一、建按月自增分区表:
    1.1建表
    SQL> create table month_interval_partition_table (id number,time_col date) partition by range(time_col)
      2  interval (numtoyminterval(1,'month'))
      3  (
      4   partition p_month_1 values less than (to_date('2014-01-01','yyyy-mm-dd'))
      5  );
     
    Table created
    1.2 查看现在分区
    SQL> select table_name,partition_name from user_tab_partitions where table_name='MONTH_INTERVAL_PARTITION_TABLE';

    1.3、插入数据
    SQL> begin
      2  for i in 0..11 loop
      3   insert into MONTH_INTERVAL_PARTITION_TABLE values(i,add_months(to_date('2014-01-01','yyyy-mm-dd'),i));
      4  end loop;
      5  commit;
      6  end;
      7  /
     
    PL/SQL procedure successfully completed

    SQL> select table_name,partition_name from user_tab_partitions where table_name='MONTH_INTERVAL_PARTITION_TABLE';

    神通kstore数据库查看分区表

    select * From V_SYS_TAB_PARTITIONS   

    1.5查看其中一个分区数据


    SQL> select * From MONTH_INTERVAL_PARTITION_TABLE partition(SYS_P22);

    二、创建按天的分区表


    2.1建表
    SQL> create table day_interval_partition_table (id number,time_col date) partition by range(time_col)
      2  interval (numtodsinterval(1,'day'))
      3  (
      4   partition p_day_1 values less than (to_date('2014-01-01','yyyy-mm-dd'))
      5  );
     
    Table created
     
    2.2、查看现在分区
    SQL> select table_name,partition_name from user_tab_partitions where table_name='DAY_INTERVAL_PARTITION_TABLE';
     
    TABLE_NAME                     PARTITION_NAME
    ------------------------------ ------------------------------
    DAY_INTERVAL_PARTITION_TABLE   P_DAY_1


    2.3、插入数据
    SQL> begin
      2  for i in 1..12 loop
      3   insert into DAY_INTERVAL_PARTITION_TABLE values(i,trunc(to_date('2014-01-01','yyyy-mm-dd')+i));
      4  end loop;
      5  commit;
      6  end;
      7  /
     
    PL/SQL procedure successfully completed


    2.4查看分区
    SQL> select table_name,partition_name from user_tab_partitions where table_name='DAY_INTERVAL_PARTITION_TABLE';

    2.5查看数据
    SQL> select table_name,partition_name from user_tab_partitions where table_name='DAY_INTERVAL_PARTITION_TABLE';

    查看某个分区数据

    select * From DAY_INTERVAL_PARTITION_TABLE partition(SYS_P39);

  • 相关阅读:
    人生中第一份值得纪念的工作
    ZOJ 3829 Known Notation(字符串处理 数学 牡丹江现场赛)
    java基础之内部类
    从计算的本质到编程语言
    【Cocos2dx】资源目录,播放背景音乐,导入外部库
    POJ 3723 Tree(树链剖分)
    hdu 1002 A + B Problem II(大正整数相加)
    时间格式字符串转化为date和时间戳
    深入浅出游戏算法(4)-unity3d算法(1)-球转动
    GeoServer手动发布本地Shapefile地图
  • 原文地址:https://www.cnblogs.com/qull/p/6656614.html
Copyright © 2011-2022 走看看