完整的解决oracle乱码shell处理(当每日导入数据库是英文字符集但需要导入中文字符集并且显示中文)

时间:2022-06-29 00:28:15

1.gs_o_convert.sh

#!/bin/sh
ORACLE_BASE=/home/oracle;export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/9.2.0;export ORACLE_HOME
ORACLE_SID=test;export ORACLE_SID
DISPLAY=192.168.10.251:0.0;export DISPLAY
PATH=$ORACLE_HOME/bin:/usr/kerberos/bin:/usr/local/java/bin:/usr/local/java/jre/bin:/usr/bin:/usr/local/bin:/bin:/usr/local/mmsdiy/apache2.2.6/bin:/etc:/usr/sbin:/usr/lbin:/usr/ucb:$HOME/bin:/usr/X11R6/bin:/usr/bin/X11:/sbin;export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib32:$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib;export LD_LIBRARY_PATH
ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data;export ORA_NLS33
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:/usr/local/java/jre/lib:/usr/local/java/lib:/usr/local/java/lib/tools.jar:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib;export CLASSPATH
NLS_LANG="SIMPLIFIED AMERICAN_AMERICA.ZHS16GBK";export NLS_LANG

#Written by Chameleon
scriptdir=/root/shell/convert_zifu/expdir
today=`date +%Y-%m-%d`
exp_dir=$scriptdir/expdir
name01=$scriptdir/GS_O_zen_export_"$today".dmp
name02=$exp_dir/GS_O_zen_CN_export_"$today".dmp
ftptodir=/home/datebak/`date +%Y-%m-%d -d "$(echo -1) day"`
#对备份文件进行删除(备份的文件只有暂时备份2个需要通过转码的表,文件非常小)
find /root/shell/convert_zifu/expdir -name 'GS_O_zen_export_*.dmp' -type d -maxdepth 1 -mtime +2 |xargs rm -rf
find /root/shell/convert_zifu/expdir/expdir -name 'GS_O_zen_CN_export_*.dmp.gz' -type d -maxdepth 1 -mtime +3 |xargs rm -rf
#开始导入
/home/oracle/product/9.2.0/bin/imp userid=back/backpass buffer=10240000 fromuser=back touser=back tables=(gs_o_ms_isdn_segment,gs_o_act_config,gs_o_mms_act_config,gs_o_sms_infocode) file=$name01
echo "import ok" > $exp_dir/log
#转中文字符集
$scriptdir/convert_to_cn.sh
echo "转中文字符 ok" >> $exp_dir/log
#开始导出
/home/oracle/product/9.2.0/bin/exp userid=back/backpass tables=(gs_o_ms_isdn_segment,gs_o_act_config,gs_o_mms_act_config,gs_o_sms_infocode) file=$name02
echo "export ok" >> $exp_dir/log
gzip $name02
echo "extract ok" >> $exp_dir/log
#删除已经导入的表
$scriptdir/drop.sh
#还原回英文字符集
$scriptdir/convert_to_en.sh
#上传到天津服务器
cd $exp_dir
ftp -i -n ip<<FTP
user datebak datebak!))*^lxmail
binary
if [ -d $ftptodir ]
then
echo "$ftptodir is exist~!"
else
mkdir -p $ftptodir
fi
put "$name02".gz $ftptodir/GS_O_zen_CN_export_"$today".dmp.gz
bye
FTP
exit

 

 

2.convert_to_en.sh

#!/bin/sh
sqlplus "/ as sysdba"<<!
shutdown immediate
STARTUP MOUNT;
--alter session set sql_trace=true;
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;
alter database open;
ALTER DATABASE character set INTERNAL_USE us7ascii;
SHUTDOWN IMMEDIATE;
STARTUP
exit

3.convert_to_cn.sh

#!/bin/sh
sqlplus "/ as sysdba"<<!
shutdown immediate
STARTUP MOUNT;
ALTER SYSTEM ENABLE RESTRICTED SESSION;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;
ALTER DATABASE OPEN;
ALTER DATABASE character set INTERNAL_USE  ZHS16GBK;
SHUTDOWN IMMEDIATE;
STARTUP
exit

4.drop.sh

#!/bin/sh
#删除以下表
#Written by Chameleon
sqlplus 'back/backpass'<<!
drop table gs_o_ms_isdn_segment;
drop table gs_o_act_config;
drop table gs_o_mms_act_config;
drop table gs_o_sms_infocode;
exit

##说明:这个一个完整的例题,使用的是一台转码服务器来处理的数据后并上传到其他服务器并进行导入

 

###版权-----found2008 ------邮箱:hiho1128@126.com