Analyze table oracle

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 22:06 点击:

vi Analyze_table.sh
#################################################################################################
## This for normal analyze,Added only after each step the following operations,
## the default is 40% of the table, all indexes of the table.
#--First enter user\/passwd\@instance,if you gotta some irregular characters,you should transfer.
#For demo enter : scott\/\"scott\@\#\$331804\"\@ucc
#--Second enter tables
#--Or nothing or add table1 or add table1,table2,......
#--Third enter tables percent?
#--Or nothing or add ESTIMATE STATISTICS SAMPLE percent? for table
#--Fourth enter indexes percent?
#--Or nothing or add ESTIMATE STATISTICS SAMPLE percent? for index
# AUTHOR : Clement Ge Mail:clement.gejun@gmail.com
#################################################################################################
#!/bin/sh
source /home/oracle/.bash_profile
paths=`pwd`
today=Analyzed_`date +%Y%m%d`
nowtime=`date +%Y_%m_%d`
sx_mail=" clement.gejun@gmail.com "
nums=$#
t1=`expr index "$1" /`
let "t2=$t1-1"
t4="'${2//,/'),UPPER('}'"
t5=${3:-40}
t6=${4:-100}
if [ $nums -lt 1 ]
  then
  "Please enter 'Oracle' user,like format: oracle\/passwd@instance as the first parameter !"
  exit 0
elif [ $nums -gt 1 ]
  then
    t7="TABLE_NAME IN (UPPER($t4))"
else
  t7="1=1"
fi
sqlplus $1 << EOF
col AC format a900
SET LINESIZE 1000
SET TERM OFF VERIFY OFF FEEDBACK OFF PAGESIZE 1000;
SPOOL $paths/ANALYTAB.sql
SELECT 'ANALYZE TABLE ' || UPPER('${1:0:$t2}') || '.' || TABLE_NAME || ' ESTIMATE STATISTICS SAMPLE ' || nvl($t5,40) || ' PERCENT FOR TABLE;'  AC FROM USER_TABLES WHERE $t7;
SPOOL OFF;
SPOOL $paths/ANALYIND.sql
SELECT 'ANALYZE TABLE ' || UPPER('${1:0:$t2}') || '.' || TABLE_NAME || ' ESTIMATE STATISTICS SAMPLE ' || nvl($t6,100) || ' PERCENT FOR ALL INDEXES;' AC FROM USER_TABLES WHERE $t7;
SPOOL OFF;
SPOOL $paths/ANALYZE_$nowtime.LOG
set timing on
set serveroutput on
@$paths/ANALYTAB.sql
@$paths/ANALYIND.sql
SPOOL OFF;
exit
!
rm -rf $paths/ANALYZE_`date -d '5 days ago' +%Y_%m_%d`.LOG
mail $sx_mail -s $today_'Table Analyzed : ' < $paths/ANALYZE_$nowtime.LOG

作者“Clement Ge 的专栏”
 

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Table函数使用简介
      • Oracle数据库Constraint约束的常用操作及异常处理
      • Bulk Collect性能分析(zz)
      • export/import的使用
      • OCP043第十五讲 Database Security
      • ORACLE10gr2数据导入MySQL方案
      • oracle 让sys用户可以使用isqlplus
      • 在oracle数据库下使用iSQL*Plus DBA访问数据库
      • Oracle行列转换小结
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1