标签:sql char sharp creat number instr open inter range
创建分区表AAA,通过字段创建时间的年份来分区,分区表自动根据插入的数据新增对应的分区,不过此处自动创建的分区名称为系统创建的,如:SYS_24。
CREATE TABLE AAA ( ID NUMBER(8), CREATETIME DATE, VALUE NUMBER(8) ) PARTITION BY RANGE(CREATETIME) INTERVAL(NUMTOYMINTERVAL(1,‘YEAR‘)) ( PARTITION P2014 VALUES LESS THAN(TO_DATE(‘2015-01-01‘,‘YYYY-MM-DD‘)) );
不过,这种分区名称难以使用,故后面会使用存储过程来修改分区表的分区名。
create or replace procedure pro_modified_partition_name as cursor partitiionList is SELECT TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME,high_value FROM USER_TAB_PARTITIONS WHERE TABLE_NAME =‘AAA‘ and instr(PARTITION_NAME, ‘SYS‘) > 0; row_p partitiionList%rowtype; pName VARCHAR2(100); hv VARCHAR2(2000); hv_year number; pNewName varchar2(100); SQL_STMT VARCHAR2(200); begin open partitiionList; for row_p in partitiionList loop pName:= row_p.PARTITION_NAME; hv:= row_p.high_value; hv_year := to_number(substr(hv,11,4))-1; pNewName := ‘P‘|| hv_year; --执行alter语句要使用动态sql(execute immediate) SQL_STMT := ‘alter table AAA rename partition ‘||pName||‘ to ‘||pNewName; execute immediate SQL_STMT; end loop row_p; close partitiionList; end;
通过分区表的high_value值来截取对应的时间,再用以修改为分区名。
标签:sql char sharp creat number instr open inter range
原文地址:http://www.cnblogs.com/kehaocheng/p/7388757.html