- [oracle@yhbd08 scripts]$ crontab -l | tail -7
-
- #每天expdp备份数据库,Add by fjzcau 2015-12-22
- 00 19 * * * /yohodata/fjzcau/scripts/yhbd08_orcl_expdp.sh > /dev/null 2>&1
-
- #每天自动重命名分区表 yhbi_retail.fact_storage_sheet ,Add by fjzcau 2015-12-24
- 00 12 * * * /yohodata/fjzcau/scripts/fact_storage_sheet_rename_partition.sh > /dev/null 2>&1
-
--Oracle 默认分区名 SYS_P 开头
- select
- table_name ,
- partition_name ,
- high_value
- from user_tab_partitions
- where table_name like 'FACT_STORAGE_SHEET_%' --and partition_name like 'SYS%'
- order by 1,2;
-
- TABLE_NAME PARTITION_NAME HIGH_VALUE
- --------------------- --------------------- ---------------
- FACT_STORAGE_SHEET_2 P0 19900101
- FACT_STORAGE_SHEET_2 SYS_P1000 20150602
- FACT_STORAGE_SHEET_2 SYS_P1001 20150603
- FACT_STORAGE_SHEET_2 SYS_P1002 20150604
- FACT_STORAGE_SHEET_2 SYS_P1003 20150605
- FACT_STORAGE_SHEET_2 SYS_P1004 20150606
-
- Oracle 自动创建分区,分区名字默认以 "SYS_P" 开头,为方便日常查询,每天中午12点自动重命名分区。
- 存储过程的执行脚本:/yohodata/fjzcau/scripts/fact_storage_sheet_rename_partition.sh
- #---------------------------------------------------------------------------#
- # Scripts : /yohodata/fjzcau/scripts/torage_sheet_rename_partition.sh
- # Author : fangjz/YOHO!
- # Date : 2015/12/24
- # Purpose : Rename Oracle partition
- # Notes : This script can be run in crontab or in other shell script.
- # Parameters :
- #---------------------------------------------------------------------------#
- # Oracle Env
- if [ -f /home/oracle/.bash_profile ]
- then
- . /home/oracle/.bash_profile
- fi
-
- bakdate=`date '+%Y%m%d%H'`
- i_pre="`hostname`_orcl"
- log=${i_pre}_fact_storage_sheet_rename_partition_${bakdate}.log
-
- sqlplus YHBI_RETAIL/yhbi_retail <<EOF > /yohodata/fjzcau/scripts/log_ora/$log
- declare
- v_sql varchar(400);
- v_table_name user_tab_partitions.table_name%type;
- v_partition_name user_tab_partitions.partition_name%type;
- v_high_value varchar(200);
- v_tmp_partition_name user_tab_partitions.partition_name%type;
-
- cursor cur is
- select
- table_name ,
- partition_name ,
- high_value
- from user_tab_partitions
- where partition_name like 'SYS%' and table_name = 'FACT_STORAGE_SHEET' ;
-
- begin
- open cur;
- loop
- fetch cur into v_table_name,v_partition_name,v_high_value;
- exit when cur%notfound;
- v_tmp_partition_name := to_char(to_date(v_high_value - 1, 'yyyymmdd'),'yyyymmdd');
- v_sql := 'alter table '|| v_table_name ||' rename partition '
- ||v_partition_name
- ||' to P' || v_tmp_partition_name;
- dbms_output.put_line( v_sql );
- execute immediate v_sql;
- end loop;
- close cur;
- end;
- /
- exit
- EOF
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22661144/viewspace-1960905/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22661144/viewspace-1960905/