oracel表的分区
程序员文章站
2022-05-02 20:34:27
1,创建表及分区
create table test
(
id varchar2(32),
months varchar2(40),
userid varchar2(...
1,创建表及分区
create table test ( id varchar2(32), months varchar2(40), userid varchar2(20) ) partition by list(months) ( partition m201404 values('201404'), partition m201405 values('201405') )
2,插入数据
insert into test values('1','201404','1'); insert into test values('2','201405','2'); insert into test values('3','201407','3');其中,前两条可以成功。第三条失败 ora-14400: 插入的分区关键字未映射到任何分区
3,添加新的分区
alter table test add partition m201406 values('201407');4,然后再插入第三条数据成功
最后查询:
select * from test;// 所有数据 select * from test partition(m201404);//分区m201404里所有数据 select * from test partition(m201405); select * from test partition(m201406);
5,创建表及列分区并添加默认分区 后期添加新的分区
create table test ( id varchar2(32), months varchar2(40), userid varchar2(20) ) partition by list(months) ( partition m201404 values('201404'), partition m201405 values('201405'), partition mdefault values(default) ) // 删除mdefault分区 alter table test drop partition mdefault; // 添加新的分区后再加上mdefault分区 alter table test add partition m201406 values('201407'); alter table test add partition mdefault values(default);
备注:对于范围分区(有默认分区的)就不能添加
create table test ( id varchar2(32), months varchar2(40), userid varchar2(20) ) partition by range(months) ( partition m201404 values less than (201405), partition m201405 values less than (201406), partition mother values less than (maxvalue) ) //下面报错:ora-14074: 分区界限必须调整为高于最后一个分区界限 alter table test add partition m201406 values less than (201407);将分区的mother去掉就可以了
create table test ( id varchar2(32), months varchar2(40), userid varchar2(20) ) partition by range(months) ( partition m201404 values less than (201405), partition m201405 values less than (201406) ) alter table test add partition m201406 values less than (201407);