Shell添加分区表

#!/bin/bash

#######

脚本名称:addpar.sh

创建时间:

描述:

########

if [ $# lt 4 ]

then

  echo “usage:$0 <par_table> <tablespace><daterang_yyyymm><flag>”

  exit 1

fi

 date_less=‘sqlplus -s use/pawd@db <<EOF

whenever sqlerror exit sql.sqlcode

set verify off

set echo off

set feedback off

set heading off

set term off

set linesize 255

set pagesize 0

select to_char(add_months(to_date(‘$3’,’yyyymm’),1),’yyyymmdd’) from dual;

exit

EOF

 

date_less_mon=‘sqlplus -s use/pawd@db <<EOF

whenever sqlerror exit sql.sqlcode

set verify off

set echo off

set feedback off

set heading off

set term off

set linesize 255

set pagesize 0

select to_char(add_months(to_date(‘$3’,’yyyymm’),1),’yyyymm’) from dual;

exit

EOF

if [ “$4” == “1” ];then

sqlplus usr/passwd@db<<EOF

alter table $1 add partition p$3 values less than (‘$date_less’) tablespace $2 initrans 2 maxtrans 255;

EOF

else

sqlplus usr/passwd@db<<EOF

alter table $1 add partition p$3 values less than (‘$date_less_mon’) tablespace $2 initrans 2 maxtrans 255;

EOF

fi

 

posted @ 2019-04-30 16:05  菜鸟MM  阅读(379)  评论(0编辑  收藏  举报