Clear the heading in Oracle spool

安稳与你 提交于 2020-01-12 07:19:44

问题


I have spooled a file before running the below command and got the output like this,

I have set heading off, feedback off

SET HEADING OFF SET FEEDBACK OFF SPOOL D:\TEST.TXT SELECT SYSDATE FROM DUAL; SPOOL OFF

OUTPUT in TEST.TXT:

SQL> SELECT SYSDATE FROM DUAL;

20-JAN-09

SQL> SPOOL OFF

How can i remove the two SQL> lines. I want only the output.

Thanks in advance.


回答1:


The command you need is:

SET ECHO OFF

However, it only works for code run from scripts, not command entered interactively. You would create a script file like this (e.g. called test.sql):

SET HEADING OFF FEEDBACK OFF ECHO OFF PAGESIZE 0
SPOOL D:\TEST.TXT 
SELECT SYSDATE FROM DUAL; 
SPOOL OFF

Then in SQL Plus run it like this:

SQL> @test

I added PAGESIZE 0 to the SET command to remove the blank line you otherwise get before the date in the output file.




回答2:


use this:

#!/bin/ksh
CONNECT_STRING=dbapp/dbapp@inst
SQLPLUS_SETTINGS="SET PAGESIZE 1000 LINESIZE 500 ECHO OFF TRIMS ON TAB OFF FEEDBACK OFF HEADING OFF"
SQL_RESULT=`sqlplus -s ${CONNECT_STRING} << EOF
${SQLPLUS_SETTINGS}
select sysdate from dual;
exit;
EOF`

echo $SQL_RESULT >output_file


来源:https://stackoverflow.com/questions/2100293/clear-the-heading-in-oracle-spool

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!