為Oracle的使用者表自動增加分區

來源:互聯網
上載者:User

為Oracle的使用者表自動增加分區

該程式可以做為一個Oracle的JOB執行在每月的28日前執行(考慮2月28天的原因),自動為該使用者下的分區表增加分區.[@more@]
create or replace procedure guan_add_partition
/*
/*為一個使用者下所有分區表自動增加分區.分區的列為date類型,分區名類似:p200706.
/*create by David
*/
as
v_table_name varchar2(50);
v_partition_name varchar2(50);
v_month char(6);
v_add_month_1 char(6);
v_sql_string varchar2(2000);
v_add_month varchar2(20);
cursor cur_part is select distinct u.table_name,max(p.partition_name) max_part_name from user_tables u,user_tab_partitions p
where u.table_name=p.table_name and u.partitioned = 'YES'
group by u.table_name;
Begin
select to_char(sysdate,'yyyymm') into v_month from dual;
select to_char(add_months(sysdate,1),'yyyymm') into v_add_month_1 from dual;
select to_char(add_months(trunc(sysdate,'mm'),2),'yyyy-mm-dd') into v_add_month from dual;
open cur_part;
loop
fetch cur_part into v_table_name,v_partition_name;
exit when cur_part%notfound;
if to_number(substr(v_partition_name,2)) <=to_number(substr(v_month,1)) then

v_sql_string :='alter table '||v_table_name||' add partition p'||v_add_month_1||
' VALUES LESS THAN ( to_date('''||v_add_month||''',''yyyy-mm-dd'') ) tablespace users';
execute immediate v_sql_string;
else
null;
end if;
end loop;
close cur_part;
end;

相關文章

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.