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.