简体   繁体   中英

Change range value in table partition

I have a big table with partitions. ex:

CREATE TABLE cust_order (
cust_id     NUMBER(10), 
start_date   VARCHAR2(25), 
amount_sold NUMBER(10,2))
PARTITION BY RANGE (START_DATE)
(  
PARTITION MAY VALUES LESS THAN ('20120601'),
PARTITION DEF VALUES LESS THAN(MAXVALUE));

I want to alter the table so that the MAY partition contains values less than '20120501' and that the data from '20120501' to '20120601' are stored in the DEF partition.

First, you should always store dates in DATE columns. Storing dates in a VARCHAR2(25) column is a recipe for problems down the line-- someone will inevitably insert a string that has an unexpected format.

Second, assuming that there are no partitions between the MAY and DEF partitions, you could split the MAY partition

ALTER TABLE cust_order
  SPLIT PARTITION may AT ('20120501')
   INTO( PARTITION may,
         PARTITION june_temp )
 UPDATE GLOBAL INDEXES;

and then merge the JUNE_TEMP and DEF partitions

ALTER TABLE cust_order
  MERGE PARTITIONS june_temp, def
   INTO PARTITION  def

I'm not sure that I see the wisdom, however, in doing this... A default partition should not generally store any data-- it's generally only there so that inserts don't error out if they have an unexpectedly large partition key. So taking the data that is already in one partition and moving it into a default partition seems rather odd. If you're just going to create a JUNE partition in the future, I'm not sure why you wouldn't just split the partitions into a MAY and JUNE partition.

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