Oracle Interval Partition 預設分割槽重新命名-指令碼

fjzcau發表於2015-12-24


  1. [oracle@yhbd08 scripts]$ crontab -l | tail -7

  2. #每天expdp備份資料庫,Add by fjzcau 2015-12-22
  3. 00 19 * * * /yohodata/fjzcau/scripts/yhbd08_orcl_expdp.sh > /dev/null 2>&1

  4. #每天自動重新命名分割槽表 yhbi_retail.fact_storage_sheet ,Add by fjzcau 2015-12-24
  5. 00 12 * * * /yohodata/fjzcau/scripts/fact_storage_sheet_rename_partition.sh > /dev/null 2>&1


--Oracle 預設分割槽名 SYS_P 開頭

  1. select
  2.   table_name ,
  3.   partition_name ,
  4.   high_value
  5. from user_tab_partitions
  6. where table_name like 'FACT_STORAGE_SHEET_%' --and partition_name like 'SYS%'
  7. order by 1,2;

  8. TABLE_NAME              PARTITION_NAME        HIGH_VALUE
  9. ---------------------  --------------------- ---------------
  10. FACT_STORAGE_SHEET_2    P0                    19900101
  11. FACT_STORAGE_SHEET_2    SYS_P1000             20150602
  12. FACT_STORAGE_SHEET_2    SYS_P1001             20150603
  13. FACT_STORAGE_SHEET_2    SYS_P1002             20150604
  14. FACT_STORAGE_SHEET_2    SYS_P1003             20150605
  15. FACT_STORAGE_SHEET_2    SYS_P1004             20150606


  1. Oracle 自動建立分割槽,分割槽名字預設以 "SYS_P" 開頭,為方便日常查詢,每天中午12點自動重新命名分割槽。
  2. 儲存過程的執行指令碼:/yohodata/fjzcau/scripts/fact_storage_sheet_rename_partition.sh

  1. #---------------------------------------------------------------------------#
  2. # Scripts : /yohodata/fjzcau/scripts/torage_sheet_rename_partition.sh
  3. # Author : fangjz/YOHO!
  4. # Date : 2015/12/24
  5. # Purpose : Rename Oracle partition
  6. # Notes : This script can be run in crontab or in other shell script.
  7. # Parameters :
  8. #---------------------------------------------------------------------------#
  9. # Oracle Env
  10. if [ -f /home/oracle/.bash_profile ]
  11. then
  12.    . /home/oracle/.bash_profile
  13. fi

  14. bakdate=`date '+%Y%m%d%H'`
  15. i_pre="`hostname`_orcl"
  16. log=${i_pre}_fact_storage_sheet_rename_partition_${bakdate}.log

  17. sqlplus YHBI_RETAIL/yhbi_retail <<EOF > /yohodata/fjzcau/scripts/log_ora/$log
  18. declare
  19. v_sql varchar(400);
  20. v_table_name user_tab_partitions.table_name%type;
  21. v_partition_name user_tab_partitions.partition_name%type;
  22. v_high_value varchar(200);
  23. v_tmp_partition_name user_tab_partitions.partition_name%type;

  24. cursor cur is
  25. select
  26.   table_name ,
  27.   partition_name ,
  28.   high_value
  29. from user_tab_partitions
  30. where partition_name like 'SYS%' and table_name = 'FACT_STORAGE_SHEET' ;

  31. begin
  32.   open cur;
  33.   loop
  34.     fetch cur into v_table_name,v_partition_name,v_high_value;
  35.     exit when cur%notfound;
  36.     v_tmp_partition_name := to_char(to_date(v_high_value - 1, 'yyyymmdd'),'yyyymmdd');
  37.     v_sql := 'alter table '|| v_table_name ||' rename partition '
  38.     ||v_partition_name
  39.     ||' to P' || v_tmp_partition_name;
  40.     dbms_output.put_line( v_sql );
  41.     execute immediate v_sql;
  42.   end loop;
  43.   close cur;
  44. end;
  45. /
  46. exit
  47. EOF

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22661144/viewspace-1960905/,如需轉載,請註明出處,否則將追究法律責任。

相關文章