oracle spool生成文件,去掉多余的东西
在网上找了一种方法:
[oracle@jumper oracle]$ more sp.sql
set heading off
set feedback off
set term off
spool a.log
@test.sql
spool off
exit
[oracle@jumper oracle]$ more test.sql
select username from dba_users;
[oracle@jumper oracle]$ sqlplus -S "/ as sysdba" @sp
[oracle@jumper oracle]$ more a.log
SYS
SYSTEM
OUTLN
SCOTT
HAWA
CSMIG
TEST
PERFSTAT
MLQIN
EYGLE
DBSNMP
WMSYS
[oracle@jumper oracle]$
set heading off
set feedback off
set term off
spool a.log
@test.sql
spool off
exit
[oracle@jumper oracle]$ more test.sql
select username from dba_users;
[oracle@jumper oracle]$ sqlplus -S "/ as sysdba" @sp
[oracle@jumper oracle]$ more a.log
SYS
SYSTEM
OUTLN
SCOTT
HAWA
CSMIG
TEST
PERFSTAT
MLQIN
EYGLE
DBSNMP
WMSYS
[oracle@jumper oracle]$
这种方法用SHELL包装时,如果使用下面这种形式:
sqlplus -S "/ as sysdba" <<!
set heading off
set feedback off
set term off
spool a.log
@test.sql
spool off
exit
!
其生成的文件还不是纯数据。只有在shell脚本中使用 sqlplus -S "/ as sysdba" @s.sql (s.sql 就是两个!之间的语句。)
才会生成纯数据。不过这可以使用grep,awk,sed这些工具过滤掉。