资源描述:
《ORACLE数据库中PARTITION的用法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Oracle9i通过引入列表分区(ListPartition),使得当前共有4种分区数据的方法,具体列出如下: 第一种范围分区 1对表进行单列的范围分区: 这使最为常用也是最简单的方法,具体例子如下: createtableemp (empnonumber(4), enamevarchar2(30), salnumber) partitionbyrange(empno) (partitione1slessthan(1000)tablespaceemp1, partitione2slessthan(2000)tablespaceemp2, partit
2、ione3slessthan(max)tablespaceemp3); insertintoemps(100,Tom,1000); insertintoemps(500,Peter,2000); insertintoemps(1000,Scott,3000); insertintoemps(1999,Bill,4000); insertintoemps(5000,Gates,6000); commit; 从emp表中选择全部的纪录如下: SQL>select*fromemp; EMPNOENAMESAL --------------------
3、------------------------------ 100Tom1000 500Peter2000 1000Scott3000 1999Bill4000 5000Gates6000 还可以按照分区进行选择: SQL>select*fromemppartition(e1); EMPNOENAMESAL -------------------------------------------------- 100Tom1000 500Peter2000 SQL>select*fromemppartition(e2) EMPNOENAMES
4、AL -------------------------------------------------- 1000Scott3000 1999Bill4000 SQL>select*fromemppartition(e3) EMPNOENAMESAL -------------------------------------------------- 5000Gates6000 使用了分区,还可以单独针对指定的分区进行truncate操作: altertableemptruncatepartitione2; 2对表进行多列的范围分区: 多列
5、的范围分区主要是基于表中多个列的值的范围对数据进行分区,例如: droptableemp; createtableemp (empnonumber(4), enamevarchar2(30), salnumber, dayintegernotnull, monthintegernotnull) partitionbyrange(month,day) (partitione1slessthan(5,1)tablespaceemp1, partitione2slessthan(10,2)tablespaceemp2, partitione3slessthan
6、(max,max)tablespaceemp3); SQL>insertintoemps(100,Tom,1000,10,6); SQL>insertintoemps(200,Peter,2000,3,1); SQL>insertintoemps(300,Jane,3000,23,11); 第二种Hash分区: hash分区最主要的机制是根据hash算法来计算具体某条纪录应该插入到哪个分区中 (问:hash算法是干什么的?呵呵,只能去看看数据结构了) hash算法中最重要的是hash函数,Oracle中如果你要使用hash分区,只需指定分区的数量即可
7、 建议分区的数量采用2的n次方,这样可以使得各个分区间数据分布更加均匀 具体例子如下: droptableemp; createtableemp( empnonumber(4), enamevarchar2(30), salnumber) partitionbyhash(empno) partitions8 storein(emp1,emp2,emp3,emp4,emp5,emp6,emp7,emp8); 怎么样?很方便吧! 第三种复合分区: 这是一种将前两种分区综合在