运维的数据库太多日分区表,因为是建立的LOCAL 索引,所以一次添加太多分区对性能有影响,就写了个SQL自动产生批量添加日分区的脚本
with xxx as
(select table_owner,table_name,max_partname,tablespace_name,START_PART_DT
from (
SELECT table_owner,table_name||'_MAX' max_partname,
CASE WHEN '&TBS_NAME' IS NULL THEN TABLESPACE_NAME ELSE '&TBS_NAME' END TABLESPACE_NAME,
table_name,
partition_name,
substr(partition_name, instr(partition_name, '_', -1)+1) START_PART_DT
FROM (select table_owner,TABLESPACE_NAME,
table_name,+
PARTITION_NAME,
RANK() OVER(partition by TABLE_OWNER, TABLE_NAME ORDER BY partition_position DESC) AA
from dba_tab_partitions where
table_name = '&TAB_NAME'
)
WHERE AA = 2 ) where length(START_PART_DT) =8 )
select 'alter table '
||a.table_owner
||'.'
||a.table_name
||' split partition '
||a.max_partname
||' at ('
||''''
||to_char((to_date(a.START_PART_DT,'yyyymmdd')+level+1 ),'yyyymmdd')
||''''
||') INTO (PARTITION '
||a.table_name
||'_'
||to_char((to_date(a.START_PART_DT,'yyyymmdd')+level ),'yyyymmdd')
||' tablespace '
||a.tablespace_name
||' STORAGE (INITIAL 64K),partition '
||a.max_partname
||' );'
from xxx a CONNECT BY LEVEL <= '&DAY';
with xxx as
(select table_owner,table_name,max_partname,tablespace_name,START_PART_DT
from (
SELECT table_owner,table_name||'_MAX' max_partname,
CASE WHEN '&TBS_NAME' IS NULL THEN TABLESPACE_NAME ELSE '&TBS_NAME' END TABLESPACE_NAME,
table_name,
partition_name,
substr(partition_name, instr(partition_name, '_', -1)+1) START_PART_DT
FROM (select table_owner,TABLESPACE_NAME,
table_name,+
PARTITION_NAME,
RANK() OVER(partition by TABLE_OWNER, TABLE_NAME ORDER BY partition_position DESC) AA
from dba_tab_partitions where
table_name = '&TAB_NAME'
)
WHERE AA = 2 ) where length(START_PART_DT) =8 )
select 'alter table '
||a.table_owner
||'.'
||a.table_name
||' split partition '
||a.max_partname
||' at ('
||''''
||to_char((to_date(a.START_PART_DT,'yyyymmdd')+level+1 ),'yyyymmdd')
||''''
||') INTO (PARTITION '
||a.table_name
||'_'
||to_char((to_date(a.START_PART_DT,'yyyymmdd')+level ),'yyyymmdd')
||' tablespace '
||a.tablespace_name
||' STORAGE (INITIAL 64K),partition '
||a.max_partname
||' );'
from xxx a CONNECT BY LEVEL <= '&DAY';
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/308563/viewspace-2136302/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/308563/viewspace-2136302/