这篇文章主要讲解了“oracle分区表可以分为几类”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“oracle分区表可以分为几类”吧!Oracle分区表分为四类:范围分区表;列表分区表;哈希分区表;组合分区表1.列表分区表(list)CREATE TABLE list_example(dname VARCHAR2(10),DATA VARCHAR2(20))PARTITION BY LIST(dname)(PARTITION part01 VALUES(‘初始登记’,’转移登记’),PARTITION part02 VALUES(‘更名登记’,’楼盘变更’),PARTITION part03 VALUES(‘抵押登记’),PARTITION part04 VALUES(‘限制登记’));2.范围分区CREATE TABLE example(CUSTOMER_ID NUMBER NOT NULL PRIMARY KEY,FIRST_NAME VARCHAR2(30) NOT NULL,LAST_NAME VARCHAR2(30) NOT NULL,PHONE VARCHAR2(15) NOT NULL,EMAIL VARCHAR2(80),STATUS CHAR(1))PARTITION BY RANGE (CUSTOMER_ID)(PARTITION exam1 VALUES LESS THAN (100000) TABLESPACE arsystem,PARTITION exam2 VALUES LESS THAN (200000) TABLESPACE arsystem,PARTITION exam3 VALUES LESS THAN (300000) TABLESPACE arsystem);时间分区CREATE TABLE part_date(ORDER_ID NUMBER(7) NOT NULL,ORDER_DATE DATE,TOTAL_AMOUNT NUMBER,CUSTOTMER_ID NUMBER(7),PAID CHAR(1))PARTITION BY RANGE (ORDER_DATE)(PARTITION ORD_ACT_PART01 VALUES LESS THAN (TO_DATE(‘2015-07-01 00:00:00′,’yyyy-mm-dd hh34:mi:ss’)) TABLESPACE arsystem,PARTITION ORD_ACT_PART02 VALUES LESS THAN (TO_DATE(‘2015-08-01 00:00:00′,’yyyy-mm-dd hh34:mi:ss’)) TABLESPACE arsystem,PARTITION ORD_ACT_PART03 VALUES LESS THAN (TO_DATE(‘2015-09-01 00:00:00′,’yyyy-mm-dd hh34:mi:ss’)) TABLESPACE arsystem,PARTITION ORD_ACT_PART04 VALUES LESS THAN (MAXVALUE)TABLESPACE arsystem);哈希分区create table HASH_PART(transaction_id number primary key,item_id number(8) not null)partition by hash(transaction_id)(partition part_01 tablespace ARSYSTEM,partition part_02 tablespace ARSYSTEM,partition part_03 tablespace ARSYSTEM);简写CREATE TABLE emp_hash(empno NUMBER (4),ename VARCHAR2 (30),sal NUMBER)PARTITION BY HASH (empno) PARTITIONS 8STORE IN (arsystem1,arsystem2);hash分区最主要的机制是根据hash算法来计算具体某条纪录应该插入到哪个分区中,hash算法中最重要的是hash函数,Oracle中如果你要使用hash分区,只需指定分区的数量即可。建议分区的数量采用2的n次方,这样可以使得各个分区间数据分布更加均匀。组合分区范围-散列分区CREATE TABLE SALES ( PRODUCT_ID VARCHAR2(5), SALES_DATE DATE, SALES_COST NUMBER(10), STATUS VARCHAR2(20) ) PARTITION BY RANGE(SALES_DATE) SUBPARTITION BY LIST (STATUS) ( PARTITION P1 VALUES LESS THAN(TO_DATE(‘2003-01-01′,’YYYY-MM-DD’))TABLESPACE ARSYSTEM ( SUBPARTITION P1SUB1 VALUES (‘ACTIVE’) TABLESPACE ARSYSTEM, SUBPARTITION P1SUB2 VALUES (‘INACTIVE’) TABLESPACE ARSYSTEM ), PARTITION P2 VALUES LESS THAN (TO_DATE(‘2003-03-01′,’YYYY-MM-DD’)) TABLESPACE ARSYSTEM ( SUBPARTITION P2SUB1 VALUES (‘ACTIVE’) TABLESPACE ARSYSTEM, SUBPARTITION P2SUB2 VALUES (‘INACTIVE’) TABLESPACE ARSYSTEM ) );范围-哈希分区create table dinya_test ( transaction_id number primary key, item_id number(8) not null, item_description varchar2(300), transaction_date date ) partition by range(transaction_date)subpartition by hash(transaction_id) subpartitions 3 store in (arsystem,users) ( partition part_01 values less than(TO_DATE(‘2015-07-01 00:00:00′,’yyyy-mm-dd hh34:mi:ss’)), partition part_02 values less than(TO_DATE(‘2015-08-01 00:00:0免费主机域名0′,’yyyy-mm-dd hh34:mi:ss’)), partition part_03 values less than(maxvalue) );在分区表上可以建立三种类型的索引:1和普通表一样的全局索引;2.全局分区索引;3.本地分区索引1.建立普通的索引create index com_index_range_example_id on range_example(id);2.建立本地分区索引create index local_index_range_example_id on range_example(id) local;3.建立全局分区索引create index gidx_range_exampel_id on range_example(id)GLOBAL partition by range(id)(part_01 values less than(1000),part_02 values less than(MAXVALUE));对于分区索引的删除,local index 不能指定分区名称,单独的删除分区索引。local index 对应的分区会伴随着data分区的删除而一起被删除。global partition index 可以指定分区名称,删除某一分区。但是有一点要注意,如果该分区不为空,则会导致更高一级的索引分区被置为UNUSABLE 。ALTER INDEX gidx_range_exampel_id drop partition part_01 ; 此句将导致part_02 状态为UNUSABLE分区表的操作1.查询select * from part_date partition(ORD_ACT_PART01);2.删除某个分区alter table part_date drop partition ORD_ACT_PART04;alter table part_date truncate partition ORD_ACT_PART04;3.添加分区ALTER TABLE part_date ADD PARTITION ORD_ACT_PART04 VALUES LESS THAN(TO_DATE(‘2015-10-01′,’YYYY-MM-DD’));4.创建索引create index idx_part_date on part_date(order_id) local;———————–在线重定义过程———————–包中的定义,可以用pl/sql工具看下包dbms_redefinition的用法 — Constants for the options_flag parameter of start_redef_table cons_use_pk CONSTANT PLS_INTEGER := 1;—主键重定义 cons_use_rowid CONSTANT PLS_INTEGER := 2;—rowid重定义增快处理速度,可添加并行alter session force parallel dml parallel 4;alter session force parallel query parallel 4;建立普通表CREATE TABLE putong_table(CUSTOMER_ID NUMBER NOT NULL PRIMARY KEY,FIRST_NAME VARCHAR2(30) NOT NULL,LAST_NAME VARCHAR2(30) NOT NULL,PHONE VARCHAR2(15) NOT NULL,EMAIL VARCHAR2(80),STATUS CHAR(1));创建分区表CREATE TABLE part_table(CUSTOMER_ID NUMBER NOT NULL PRIMARY KEY,FIRST_NAME VARCHAR2(30) NOT NULL,LAST_NAME VARCHAR2(30) NOT NULL,PHONE VARCHAR2(15) NOT NULL,EMAIL VARCHAR2(80),STATUS CHAR(1))PARTITION BY RANGE (CUSTOMER_ID)(PARTITION exam1 VALUES LESS THAN (100000) TABLESPACE arsystem,PARTITION exam2 VALUES LESS THAN (200000) TABLESPACE arsystem,PARTITION exam3 VALUES LESS THAN (300000) TABLESPACE arsystem);插入测试数据insert into putong_table values(1,’43t’,’f4y’,’t54′,’th’,’3′);insert into putong_table values(2,’43t’,’f4y’,’t54′,’th’,’2′);insert into putong_table values(3,’43t’,’f4y’,’t54′,’th’,’1′);在线重定义过程测试该表是否可分区exec dbms_redefinition.can_redef_table(‘ARADMIN’, ‘putong_table’);开始EXEC DBMS_REDEFINITION.START_REDEF_TABLE(‘ARADMIN’, ‘putong_table’, ‘part_table’);–插入测试数据(可选)insert into putong_table values(4,’43t’,’f4y’,’t54′,’th’,’4′);同步数据EXEC dbms_redefinition.sync_interim_table(‘ARADMIN’, ‘putong_table’, ‘part_table’);完成EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE(‘ARADMIN’, ‘putong_table’, ‘part_table’);将分区表重命名alter table part_table rename to part_table_new;1.无主键表普通表CREATE TABLE date_putong(ORDER_ID NUMBER(7) NOT NULL,ORDER_DATE DATE,TOTAL_AMOUNT NUMBER,CUSTOTMER_ID NUMBER(7),PAID CHAR(1));分区表CREATE TABLE date_partition(ORDER_ID NUMBER(7) NOT NULL,ORDER_DATE DATE,TOTAL_AMO免费主机域名UNT NUMBER,CUSTOTMER_ID NUMBER(7),PAID CHAR(1))PARTITION BY RANGE (ORDER_DATE)(PARTITION ORD_ACT_PART01 VALUES LESS THAN (TO_DATE(‘2015-07-01 00:00:00′,’yyyy-mm-dd hh34:mi:ss’)) TABLESPACE arsystem,PARTITION ORD_ACT_PART02 VALUES LESS THAN (TO_DATE(‘2015-08-01 00:00:00′,’yyyy-mm-dd hh34:mi:ss’)) TABLESPACE arsystem,PARTITION ORD_ACT_PART03 VALUES LESS THAN (TO_DATE(‘2015-09-01 00:00:00′,’yyyy-mm-dd hh34:mi:ss’)) TABLESPACE arsystem,PARTITION ORD_ACT_PART04 VALUES LESS THAN (MAXVALUE)TABLESPACE arsystem);插入数据insert into date_putong values(1,TO_DATE(‘2015-08-24′,’yyyy-mm-dd’),1,2,3);insert into date_putong values(1,TO_DATE(‘2015-08-24′,’yyyy-mm-dd’),1,2,3);insert into date_putong values(1,TO_DATE(‘2015-08-24′,’yyyy-mm-dd’),1,2,3);重定义过程exec dbms_redefinition.can_redef_table(‘ARADMIN’, ‘date_putong’,2);EXEC DBMS_REDEFINITION.START_REDEF_TABLE(‘ARADMIN’, ‘date_putong’, ‘date_partition’,null,2);EXEC dbms_redefinition.sync_interim_table(‘ARADMIN’, ‘date_putong’, ‘date_partition’);EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE(‘ARADMIN’, ‘date_putong’, ‘date_partition’);————–异常处理————–异常情况下终止操作BEGIN DBMS_REDEFINITION.ABORT_REDEF_TABLE(uname => ‘ARADMIN’, orig_table => ‘date_putong’, int_table => ‘date_partition’ );END;或DBMS_REDEFINITION.ABORT_REDEF_TABLE(‘ARADMIN’, ‘date_putong’, ‘date_partition’);ORA-12089: 不能联机重新定义无主键的表 “ARADMIN”.”DATE_PUTONG”ORA-06512: 在 “SYS.DBMS_REDEFINITION”, line 56ORA-06512: 在 “SYS.DBMS_REDEFINITION”, line 1498ORA-06512: 在 line 2alter table PUTONG_TABLE add primary key (CUSTOMER_ID)ORA-12091删除物化视图日志drop materialized view log on BS_T_WF_DEALPROCESS_BAK;查看分区时的错误select * from DBA_REDEFINITION_ERRORS;虚拟列分区举例要求按月进行分区,并且这12个分区可以循环使用,只保留2个月的数据,所以使用11g的虚拟列进行分区create table MACHINE_TEMP_part( id NUMBER, username VARCHAR2(30), tcp VARCHAR2(30), clientip VARCHAR2(30), logintime VARCHAR2(30), logouttime VARCHAR2(30), serverip VARCHAR2(30), insertdate DATE, part_numas (to_nubmer(to_char(insertdate,’mm’))))tablespace UNIONMONartition by range(partition_num)(partition p1 values less than(2),partition p2 values less than(3),partition p3 values less than(4),partition p4 values less than(5),partition p5 values less than(6),partition p6 values less than(7),partition p7 values less than(8),partition p8 values less than(9),partition p9 values less than(10),partition p10 values less than(11),partition p11 values less than(12),partition p12 values less than(13));感谢各位的阅读,以上就是“oracle分区表可以分为几类”的内容了,经过本文的学习后,相信大家对oracle分区表可以分为几类这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是云技术,小编将为大家推送更多相关知识点的文章,欢迎关注!
相关推荐: redis之RDB、AOF与复制时对过期键怎么处理
这篇文章将为大家详细讲解有关redis之RDB、AOF与复制时对过期键怎么处理,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。生成RDB文件在执行SAVE命令或者BGSAVE命令创建一个新的RDB文件时,程序会对数据库中的键进…