oracle-sql腳本導出EXCEL數據


在數據庫中,經常有業務人員提出需求導出數據庫中的業務數據,而且是每天、每周或每月定時導出。為了方便,可將sql查詢的腳本 通過下面腳本來導出EXCEL數據。

1.將查詢sql腳本(AAA.sql)放到 相關目錄如:/home/oracle/tongji-scripts/sql/AAA.sql

2.# vim  sql-excel.sh

source /home/oracle/.bash_profile
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export LANG=zh_CN.GBK

function EXESQL(){
sqlplus -s test/"123456" <<EOF
set linesize 200
set term off verify off feedback off pagesize 999
set markup html on entmap ON spool on preformat off
spool /home/oracle/tongji-scripts/result/$1_`date +%y%m%d`.xls
@/home/oracle/tongji-scripts/sql/$1;
spool off
exit;
EOF
}

for file in `ls /home/oracle/tongji-scripts/sql/`
do
EXESQL ${file}
done

3.添加定時任務: 00  03  *  *   *  /home/oracle/sql-excel.sh

每天定時3點會將 /home/oracle/tongji-scripts/sql/下面的多個sql腳本導出 生成EXCEL文件 存放到 /home/oracle/tongji-scripts/result/目錄下。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM