shell脚本执行oracle删除表,实战:oracle删除表空间的shell脚本

#!/bin/bash

[email protected]

#drop tablespace

if [ $# -ne 1 ]; then

echo "Usage: $0 TABLESPACE_NAME "

exit 1

fi

#configure oracle env:about oracle envs, username and password

ORACLE_SID=orcl

ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

ora_data=/u01/app/oracle/product/11.2.0/db_1/dbs/

ora_user="sys"  #oracle username

ora_pass="password"  #oracle user password

tablespace_name=$(echo $1 | tr ‘[a-z]‘ ‘[A-Z]‘)

outfiletmp=/tmp/droptpstmp01.txt  #specify the output file location

sqlplus -S "${ora_user}/${ora_pass} as sysdba" </dev/null #禁止sqlplus执行结果回显

set heading off;

set feedback off;

set termout off;

set pagesize 0;

set verify off;

set echo off;

spool ${outfiletmp}

select tablespace_name from dba_tablespaces where tablespace_name=‘${tablespace_name}‘;

spool off

exit;

!01

tps_jug=`grep -i ${tablespace_name} ${outfiletmp} `

if [ "${tps_jug}" = "${tablespace_name}" ]; then

wind_var=$(

sqlplus -s "{ora_user}/${ora_pass} as sysdba" <

set heading off

drop tablespace ${tablespace_name} including contents and datafiles;

EXIT;

EOF)

echo -e "\e[1;32m  ${wind_var} \e[0m"   #Direct display returns results

exit 1

else

echo -e "\e[1;31m --------------------------------------- \e[0m"

echo -e "\e[1;31m  The tablespace ${tablespace_name} not exits! \e[0m"

echo -e "\e[1;31m --------------------------------------- \e[0m"

exit 1

fi

rm -rf ${outfiletmp}

原文:http://blog.csdn.net/yangzhawen/article/details/39549315

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值