Oracle:管理 date類型 interval 動態變化的分區:查詢、刪除

來源:互聯網
上載者:User
-- 建立暫存資料表,目的是擷取long類型的:high_value 的值drop table syscom_tab_partition_temp purge;create table prm8_user.syscom_tab_partition_temp (table_name varchar2(30),partition_position int,partition_name varchar(30),high_value clob, dt date );-- 清理之前的臨時資料delete from syscom_tab_partition_temp a where a.table_name=upper('partition_table_name');;-- 擷取partition表的分區資訊insert into syscom_tab_partition_temp(table_name,partition_position,partition_name,high_value)select a.table_name,a.partition_position,a.partition_name,to_lob(a.high_value)from user_tab_partitions  awhere a.table_name=upper('partition_table_name');--特殊 date interval 類型表的 date值的處理update syscom_tab_partition_tempset dt=to_date(substr(trim(to_char(high_value)),11,19),'SYYYY-MM-DD HH24:MI:SS')where table_name=upper('partition_table_name');--擷取刪除指令碼select p.*       ,'alter table ' || p.table_name || ' drop partition ' || p.partition_name || ';' as d_sqlfrom syscom_tab_partition_temp pwhere p.table_name=upper('partition_table_name')     and p.partition_name<>upper('PTN_DUMMY')     and p.dt<trunc(sysdate - 180 ) -- 180 dayorder by p.partition_position desc;--重新查詢select a.table_name,a.partition_position as pos,a.partition_name,a.interval,a.high_value,a.tablespace_name,a.num_rows,a.blocks,a.last_analyzed,a.empty_blocks,a.composite,a.subpartition_count,a.parent_table_partitionfrom user_tab_partitions  awhere a.table_name=upper('partition_table_name')      and a.interval=upper('yes')order by a.table_name,a.partition_position;--更新統計資料begin      dbms_stats.gather_table_stats(ownname => user,tabname => 'partition_table_name',cascade => true);end;/

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.