Shell 数据库文件卸数成多个txt文件
/bin/bash
##############
脚本名称:unload.sh
作者:
描述:
参数描述:
修改记录:
###############
if [ $# lt 4 ]
then
echo “usage : $0 <sqlname><date><parallenum><says>”
exit 1
fi
date
cd /th/in
if [ ! -d $4 ];
then mkdir $4
else
if [ ‘find $4 / -name $1_$2* |wc -l’ -gt 0 ] ;then
rm -f $4/$1_*$2*
fi
fi
if [ ! -f /th/sql/$1.sql ];
then
echo “脚本不存在”
echo “run_sqlplus_command()=1”
exit 1
fi
date
#并行生成卸数文件
if [ $1 -eq 1 ]; then
filename=$1_1_$2.txt
/ocildr/bin/ocildr user=user pswd=pass dbname=orca sql=/th/$1.sql file=/th/in/$4/$filename array=50
record=“0x0a” field=“” arg:date=$2
#sqlplus $DB<<EOF &
#/th/$1.sql $2 $filename
#EOF
if [ $? -ne 0 ] ;then
echo”run_sqlplus_command()=1”
echo “$filename文件生成失败”
exit 1
fi
else
for ((i=1;i<=$3;i++)); do
filename=$1_$(i)_$2.txt
/ocildr/bin/ocildr user=user pswd=pass dbname=orca sql=/th/$1.sql file=/th/in/$4/$filename array=50
record=“0x0a” field=“” arg:date=$2 arg:slice=$i &
#sqlplus $DB<<EOF &
#/th/$1.sql $2 $filename $i
#EOF
if [ $? -ne 0 ] ;then
echo”run_sqlplus_command()=1”
echo “$filename文件生成失败”
exit 1
fi
done
fi
wait
date
cd /th/in
num=‘find $4/ -name $1_*$2* | wc -l|awk ‘{print $1}’’
echo “存在$num个匹配模式$1 的文件”
if [ $num -ge 1 ] && [ $num -le $3]; then
sh /th/flag.sh
if [ $? -ne 0 ];
then
exit 1
fi
else
echo “应该生成”$3”个文件结果生成”$num”个文件”
echo”run_sqlplus_command()=1”
exit 1
fi
date
t.sql
select
rpad(nvl(a,’ ’),8,’ ’),
f_get_number(b*1000,15)
from tb
where date= :date
and dbms_utility.get_hash_value(a,1,8)=:slice