简体   繁体   中英

Oracle 10g Range Partition Query

How can I partition by range for: one for pubdate values less than Jan 1, 2000; one for pubdate values greater than or equal to Jan 1, 2000 and less than Jan 1, 2010; and a third partition for all pubdate values greater than or equal to Jan 1, 2010.

How can I write my query for the partition part? I've tried to look up examples, but I just don't understand what to put after partition.

My query is here:

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);

Try this:

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));

The order of the partitions must be ascending so partition TWO is created first as it is less than the year 2000 while ONE is therefore between 2000 and 2009. The keyword MAXVALUE basically means no upper value, or, anything on or after 1st January 2010.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM