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