Oracle partition maintenance (using procedure)

Source: Internet
Author: User

Oracle partition maintenance (using procedure) Java code create or replace procedure tables (tab_name in varchar2) as var_tab_name varchar2 (32); var_tab_bak_name varchar2 (32); var_partition varchar2 (32 ); var_less_than varchar2 (8); var_flag number; begin select upper (tab_name) into var_tab_name from dual; select upper (tab_name | '_ Bak') into var_tab_bak_name from dual; select count (1) into var_flag from user_segments where segment_name = var_tab_name and partition_name like '%' | to_char (sysdate, 'yyyy _ mm '); select var_tab_name | '_' | to_char (sysdate, 'yyyy _ mm') into var_partition from dual; select to_char (add_months (sysdate, 1), 'yyyymm ') | '01' into var_less_than from dual; if var_flag = 0 then -- if the current month partition does not exist, execute immediate 'alter table' | var_tab_name | 'add partition' | var_partition | 'values less than ('| var_less_than | ')'; end if; select count (1) into var_flag from user_segments where segment_name = var_tab_bak_name and partition_name like '%' | to_char (add_months (sysdate,-4 ), 'yyyy _ mm'); if var_flag = 0 then select var_tab_bak_name | '_' | to_char (add_months (sysdate,-4), 'yyyy _ mm ') into var_partition from dual; select to_char (add_months (sysdate,-3), 'yyyymm') | '01' into var_less_than from dual; -- if the backup table partition does not exist, the backup monthly partition execute immediate 'alter table' | var_tab_bak_name | 'add partition' | var_partition | 'values less than ('| var_less_than |') 'is added ')'; -- select var_tab_name | '_' | to_char (add_months (sysdate,-4), 'yyyy _ mm') into var_partition from dual; execute immediate 'insert' | var_tab_bak_name | 'select * from' | var_tab_name | 'partition ('| var_partition | ')'; /* insert into var_tab_bak_name select * from var_tab_name partition (var_partition); */commit; -- delete the backup month partition execute immediate 'alter table' | var_tab_name | 'drop partition' | var_partition; end if; end;

Related Article

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.