2.编辑 main.sql
-
[oracle@testdb ~]$ cat main.sql
-
set linesize 200 pagesize 10000
-
set term off verify off feedback off
-
set markup html on entmap on spool on preformat off
-
alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
-
spool /home/oracle/test1.xls
-
@/home/oracle/get_tables.sql
-
spool off
-
exit
3.编辑 get_tables.sql
-
[oracle@testdb ~]$ cat get_tables.sql
-
select * from test1;
4.编辑执行文件 collect.sh
-
[oracle@testdb ~]$ cat collect.sh
-
#!/bin/bash
-
. /home/oracle/.bash_profile
-
DATE=`date +%Y%m%d`
-
sqlplus sam/oracle@dzwj @/home/oracle/main
-
mv /home/oracle/test1.xls /home/oracle/test1_${DATE}.xls
5.给collect.sh 执行权限
-
[oracle@testdb ~]$ chmod u+x collect.sh
6.执行
-
[oracle@testdb ~]$ ./collect.sh
-
-
SQL*Plus: Release 11.2.0.4.0 Production on Wed Nov 29 11:00:19 2017
-
-
Copyright (c) 1982, 2013, Oracle. All rights reserved.
-
-
-
Connected to:
-
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
-
With the Partitioning, OLAP, Data Mining and Real Application Testing options
-
-
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
-
With the Partitioning, OLAP, Data Mining and Real Application Testing options
7.验证
将文件传回到本地机器打开,得到想要的excel文件
三、总结
生活在Internet时代真是件幸福的事,此次任务算是告一段落,但是当中还是碰到一些小problems,比如一开始没有加时间NLS_DATE_FORMAT变量的修改,导出的时间类型数据时没有时间,只有年月日。总而言之,多学习,多实践,没错的。向eygle大神致谢。 Where there is a will, there is a way.