oracle split分区脚本

declare 
v_sql varchar2(1000);
BEGIN
    FOR outcur IN ( 
      select '20180719' partition_time,'GSCS_IIGLOG' as table_name from dual union all
      select '20180719' partition_time,'SFCS_SSLOG' as table_name from dual union all
      select '20180719' partition_time,'POCS_PINGPGLOG' from dual  
     ) 
    LOOP   

        FOR cur IN ( select  dt.table_name,'P'||to_char( to_date(p2,'yyyymmddhh24') +2/24,'yyyymmddhh24')  as P1
                         , 'P'|| to_char(to_date(dt.p2,'yyyymmddhh24') +1/24,'yyyymmddhh24') as  p2
                     from (
                        select b.table_name
                        ,b.dates|| lpad( a.hours,2,0) as P2
                          from 
                          (with x as
                            ( select 'mengl' chr from dual)
                            select level-1 as hours  from x connect by level <= 24
                            order by 1 desc) a,(  SELECT outcur.table_name as table_name , outcur.partition_time dates from dual) b
                         ) dt
             )
          LOOP
            BEGIN
             v_sql:=' alter table '|| cur.table_name||' split partition '|| cur.p1||' at(TIMESTAMP'''|| to_char(to_date(substr(cur.p2,2),'yyyymmddhh24'),'yyyy-mm-dd hh24:mi:ss') ||''') into (
                      partition '|| cur.p2||' ,partition '|| cur.p1||'  ) ';

      execute immediate(v_sql); 
     -- dbms_output.put_line(v_sql); 
      EXCEPTION WHEN OTHERS THEN
        null;
        
            END;
          END LOOP;
 END LOOP;     
    
END;
 

 

打印出来看看呢:

 

 

 

改变表空间位置

declare 
v_sql varchar2(1000);
BEGIN
    FOR outcur IN ( 
      select '20180719' partition_time,'FCS_INTETIGLOG' as table_name from dual union all
      select '20180719' partition_time,'GSACS_SMOG' as table_name from dual union all
      select '20180719' partition_time,'SASFCS_PIONGOG' from dual 
     ) 
    LOOP   

      --  FOR cur IN ( select * from user_tab_partitions where table_name=outcur.table_name and partition_name like '%20180717%' and partition_name<>'P2018071800')
              FOR cur IN ( select * from user_tab_partitions where table_name=outcur.table_name  and partition_name='P2018072100')
          LOOP
            BEGIN
             v_sql:=' alter table '|| cur.table_name||' move partition '|| cur.partition_name ||' tablespace TBAPP_UNI_BMW_1DAY007 ';
                        
      execute immediate(v_sql); 
     -- dbms_output.put_line(v_sql); 
      EXCEPTION WHEN OTHERS THEN
        null;
        
            END;
          END LOOP;
 END LOOP;     
    
END; 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值