我如何按范围分区:一个用于小于 2000 年 1 月 1 日的 pubdate 值;一个用于大于或等于 2000 年 1 月 1 日且小于 2010 年 1 月 1 日的 pubdate 值;以及所有 pubdate 值大于或等于 2010 年 1 月 1 日的第三个分区。
如何编写对分区部分的查询?我试图查找示例,但我只是不明白分区后该放什么。
我的查询在这里:
CREATE table lab6_zl (
ID number not null,
title varchar2(40),
pubID char(3),
pubdate date,
constraint lab6_pk primary key(ID))
Partition by range (pubdate)
(Partition one for pubdate values greater than or equal to Jan 1, 2000),
(Partition two for for pubdate values less than Jan 1, 2000),
(Partition three for all pubdate values greater than or equal to Jan 1, 2010);
最佳答案
尝试这个:
create table LAB6_ZL
(
ID number not null
,TITLE varchar2(40)
,PUBID char(3)
,PUBDATE date
,constraint LAB6_PK primary key(ID)
)
partition by range (PUBDATE)
(partition TWO
values less than (date '2000-01-01')
,partition ONE
values less than (date '2010-01-01')
,partition THREE
values less than (MAXVALUE));
分区的顺序必须是升序所以分区
TWO
首先创建,因为它小于 2000 年,而 ONE
因此是在 2000 年到 2009 年之间。关键字 MAXVALUE
基本上意味着没有上限值,或者 2010 年 1 月 1 日或之后的任何值。
关于sql - Oracle 10g 范围分区查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9419832/