SQL语句(四)

          Oracle使用分区技术(Partition)管理大数据,分区技术把一个表分成几部分,每一部分叫做一个分区,分布在不同的物理磁盘,以提高数据库的性能。

       1.分区方法包括:

范围分区(range partitioning):根据表中列的值进行分区

列表分区(list partitioning):使用列表值进行分区

哈希分区(hash partitioning):使用哈希函数进行分区

复合分区(composite partitioning):综合使用多种方法进行分区

1.范围分区
create table people
(
    id number,age int not null,address varchar2(100)
)
partition by range (age)
(
    partition p1 values less then (10) tablespace users,
    partition p2 values less then (20) tablespace myspace,
    partition p3 values less then (30) tablespace users,
    partition p4 values less then (70) tablespace myspace
);

2.哈希分区
create table people (id number,age number)
partition by hash(age) partition 4;
或者
create table people (id number,age number)
partition by hash(age) 
(
    partition p1 tablespace users,
    partition p2 tablespace myspace,
    partition p3 tablespace users,
    partition p4 tablespace myspace
);


3.列表分区
create table people (name varchar2(20),city varchar2(20))
partition by list(city)
(
    partition p1 values ('广东','广西') tablespace users,
    partition p2 values ('云南','西藏') tablespace users,
);

2.查询分区数据

1.查询指定分区的数据
select * from people partition(p2)

2.添加分区
alter table people add partition pa values less than(90) tablespace users ;

3.截断分区
alter table people truncate partition p1;

4.合并分区
alter table people merge partition p1,p2 into partition p2 ;

5.重命名分区
alter table people rename partition p3 to p5 ;

猜你喜欢

转载自blog.csdn.net/aganliang/article/details/86551499
今日推荐