sqlldr从数据库获取数据并上传到服务器

来源:互联网 发布:sql中all的用法 编辑:程序博客网 时间:2024/06/08 20:06

1、需求:

 sqlldr从数据库获取数据并上传到服务器


2、查询目标数据的sql语句文件(INTERFACE_test_RESULT.sql),文件里内容如下:

SELECT name, age from emp;


3、执行sh脚本(INTERFACE_RESULT.sh),文件里内容如下:

#!/bin/bash
. $HOME/.bash_profile

export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
v_out_path="/test_out/test/test_return_data"
v_out_file="test_order_"`date "+%Y%m%d"`


echo "deal old file"
cd $v_out_path
#rm -rf $v_out_path/*.txt
#mv $v_out_path/*.txt $c_out_path/data_backup/
#mv *.txt data_backup/


cd /test_out/test/test_sqlldr/
echo "spool begin..."
sqlplus -s test_out/test_out@127.12.12.12:1521/wxclyy<<EOF
set trimspool on
set linesize 120
set pagesize 0
set newpage 1
set heading off
set term off
set feedback off
--update tbl_interface_export_result set f_result = substr(f_result,1,2);
--commit;
--exec prc_data_4g_yupan;
spool $v_out_path/$v_out_file.txt
@INTERFACE_test_RESULT.sql;
spool off
exit;
EOF
echo "spool end..."
sed -i '/^$/d' $v_out_path/$v_out_file.txt
echo "del null row.."

#ftp 开始
#如果需要通过ftp上传到别的服务器,则使用以下脚本,如果只是当前sh脚本所有服务器,则不需要以下脚本
ftpserver=127.0.0.1

#指定的是用户名test,密码test
echo "user test test" > test_order_ftp.txt
echo "bin" >> test_order_ftp.txt
echo "put $v_out_path/$v_out_file.txt $v_out_file.txt" >> test_order_ftp.txt
echo "bye" >> test_order_ftp.txt

ftp -n $ftpserver < test_order_ftp.txt

#ftp 结束


#cp $v_out_path/$v_out_file.txt $v_out_path/data_backup/
#echo "file backup.."
echo "End time: "`date "+%Y-%m-%d %H:%M:%S"`


4、如果有ftp上传,则还需要以下文件test_order_ftp.txt

user test test
bin
put /test_out/test/test_return_data/test_call_20170812.txttest_call_20170812.txt
bye


5、执行sh脚本

   ./INTERFACE_RESULT.sh



阅读全文
0 0