范围分区
a.新建一个分区表,通过过程来自动添加或者删除分区:
create table sale_data(sale_id number(5), saleman_name varchar2(30), sales_mount number(10), sales_date date)partition by range (sales_date) ( partition sales_2014_1 values less than (to_date('01/02/2014','DD/MM/YYYY')), partition sales_2014_2 values less than (to_date('01/03/2014','DD/MM/YYYY')), partition sales_2014_3 values less than (to_date('01/04/2014','DD/MM/YYYY')), partition sales_2014_4 values less than (to_date('01/05/2014','DD/MM/YYYY')), partition sales_2014_5 values less than (to_date('01/06/2014','DD/MM/YYYY')), partition sales_2014_6 values less than (to_date('01/07/2014','DD/MM/YYYY')), partition sales_2014_7 values less than (to_date('01/08/2014','DD/MM/YYYY')), partition sales_2014_8 values less than (to_date('01/09/2014','DD/MM/YYYY')), partition sales_2014_9 values less than (to_date('01/10/2014','DD/MM/YYYY')), partition sales_2014_10 values less than (to_date('01/11/2014','DD/MM/YYYY')), partition sales_2014_11 values less than (to_date('01/12/2014','DD/MM/YYYY')), partition sales_2014_12 values less than (to_date('01/01/2015','DD/MM/YYYY')), partition sales_2015_1 values less than (to_date('01/02/2015','DD/MM/YYYY')), partition sales_2015_2 values less than (to_date('01/03/2015','DD/MM/YYYY')), partition sales_2015_3 values less than (to_date('01/04/2015','DD/MM/YYYY')), partition sales_2015_4 values less than (to_date('01/05/2015','DD/MM/YYYY')), partition sales_2015_5 values less than (to_date('01/06/2015','DD/MM/YYYY')), partition sales_2015_6 values less than (to_date('01/07/2015','DD/MM/YYYY')), partition sales_2015_7 values less than (to_date('01/08/2015','DD/MM/YYYY')) );
SQL> select segment_name,partition_name from user_segments where segment_name='SALE_DATA' order by partition_name desc; SEGMENT_NAME PARTITION_NAME -------------------- -------------------- SALE_DATA SALES_2015_7 SALE_DATA SALES_2015_6 SALE_DATA SALES_2015_5 SALE_DATA SALES_2015_4 SALE_DATA SALES_2015_3 SALE_DATA SALES_2015_2 SALE_DATA SALES_2015_1 SALE_DATA SALES_2014_9 SALE_DATA SALES_2014_8 SALE_DATA SALES_2014_7 SALE_DATA SALES_2014_6 SALE_DATA SALES_2014_5 SALE_DATA SALES_2014_4 SALE_DATA SALES_2014_3 SALE_DATA SALES_2014_2 SALE_DATA SALES_2014_12 SALE_DATA SALES_2014_11 SALE_DATA SALES_2014_10 SALE_DATA SALES_2014_1 19 rows selected.
CREATE OR REPLACE PROCEDURE drop_partition AS v_part_name VARCHAR2(100); v_over_time VARCHAR2(100); v_err_num NUMBER(10); v_err_msg VARCHAR2(10); BEGIN SELECT MIN(partition_name) INTO v_part_name FROM user_tab_partitions WHERE table_name = 'SALE_DATA'; --找到当前最早的分区 --取的最早分区到当前时间的间隔 SELECT months_between(SYSDATE, to_date(substr(MIN(partition_name), 7, 8), 'yyyy-mm')) INTO v_over_time FROM user_tab_partitions WHERE table_name = 'SALE_DATA'; IF v_over_time > 15 THEN EXECUTE IMMEDIATE 'alter table sale_data drop partition ' || v_part_name; END IF; EXCEPTION WHEN OTHERS THEN v_err_num := SQLCODE; v_err_msg := substr(SQLERRM, 1, 100); dbms_output.put_line('Error' || v_err_num || 'Des' || v_err_msg); END;
DECLARE job NUMBER; BEGIN dbms_job.submit(job, 'drop_partition;', SYSDATE, 'sysdate+1'); END;
SQL> exec drop_partition; PL/SQL procedure successfully completed. SQL> select segment_name,partition_name from user_segments where segment_name='SALE_DATA' order by partition_name desc; SEGMENT_NAME PARTITION_NAME -------------------- -------------------- SALE_DATA SALES_2015_7 SALE_DATA SALES_2015_6 SALE_DATA SALES_2015_5 SALE_DATA SALES_2015_4 SALE_DATA SALES_2015_3 SALE_DATA SALES_2015_2 SALE_DATA SALES_2015_1 SALE_DATA SALES_2014_9 SALE_DATA SALES_2014_8 SALE_DATA SALES_2014_7 SALE_DATA SALES_2014_6 SALE_DATA SALES_2014_5 SALE_DATA SALES_2014_4 SALE_DATA SALES_2014_3 SALE_DATA SALES_2014_2 SALE_DATA SALES_2014_12 SALE_DATA SALES_2014_11 SALE_DATA SALES_2014_10 18 rows selected.
分区技术学习一
原创
©著作权归作者所有:来自51CTO博客作者llc018198的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
linux学习(一)
linux系统部分学习。包括进程管理,文件管理的详解,以及环境变量,进程间通信,信号等的认识。
进程地址空间 文件系统 进程间通信 环境变量 信号 -
MySQL分区技术 (一)
MySQL分区技术 (一)
MySQL分区技术 一 MySQL mysql 数据 -
mysql分区技术
基本概念 把一个表,从逻辑上分成多个
字段 主键 存储数据 -
linux分区学习[ CentOS ]
分区及格式化
linux 分区 centos