How to create and operate a partitioned table

Source: Internet
Author: User
Create a partition:/***** create a partition table *****/create table sales (dopetno number, shopid varchar2 (20), shopname varchar2 (20), tdate date) partition by range (tdate) (partition p_2007_min values less than (to_date ('00:00:00 ', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '), partition p_2008 values less than (to_date ('00:00:00', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '), partition p_2009 values less than (to_date ('00:00:00', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '), partition p_2010 values less than (to_date ('00:00:00', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '), partition p_2011 values less than (to_date ('00:00:00', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '), partition p_2012 values less than (to_date ('00:00:00', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '), partition p_2013 values less than (to_date ('00:00:00', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '), partition p_2014_max values less than (maxvalue);/*** single-query Partition Table **/select * from sales partition (p_2007_min ); select * from sales partition (p_2008); select * from sales partition (p_2009); select * from sales partition (p_2010); select * from sales partition (p_2011 ); select * from sales partition (p_2012); select * from sales partition (p_2013); select * from sales partition (p_2014); select * from sales partition (p_2015 ); select * from sales partition (p_2016_max); delete a partition: /***** extended partition table *****/-- Create Table sales_tmp as select * from sales where 1 = 2; -- put the last partition data, insert into sales_tmp select * from sales partition (p_2014_max); -- Delete the last partition alter table sales drop partition p_2014_max; -- new partition 1 alter table sales add partition p_2014 values less than (to_date ('00:00:00 ', 'syyyy-MM-DD hh24: MI: ss ', 'nls _ calendar = Gregorian '); -- new partition 2 alter table sales add partition p_2015 values less than (to_date ('00:00:00', 'syyyy-MM-DD hh24: mi: ss', 'nls _ calendar = Gregorian '); -- adds a new partition 3 alter table sales add partition p_2016_max values less than (maxvalue ); -- Insert the data in the temporary table to the new table insert into sales select * From sales_tmpdrop table sales_tmp;/** the end **/other operations: select * from sales where to_char (tdate, 'yyyy')> = '000000' and to_char (tdate, 'yyyy') <= '000000' Delete from sales where to_char (tdate, 'yyyy')> = '000000' is similar to other common table operations. there is no big difference. note. partition tables are divided into several types. The preceding operations are range partitions. other operations have different rules.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.