结果文件中的SQL头

时间:2015-03-20 18:06:06

标签: sql oracle shell

我有一个SQL脚本:

SET HEADING OFF
SET ECHO OFF
SET FEEDBACK OFF
SET NEWPAGE NONE
SET PAGESIZE 0
SET TRUNCATE ON
SET VERIFY OFF

select
  count(case when msg_id like 'R%' and corr_id like 'F%' then 1 end) as Fid_Incoming ,
  count(case when msg_id like 'E%' and corr_id like 'F%' then 1 end) as Fid_Outgoing,
  count(case when msg_id like 'R%' and corr_id like 'E%' then 1 end ) as Equi_Incoming ,
  count(case when msg_id like 'E%' and corr_id like 'E%' then 1 end) as Equi_Outgoing
 from tb_msg
 where soc_id = 'WINDOWS'
 and msg_date >= trunc(sysdate);
 quit

如果从sqlplus调用,则返回以下内容:

FID_INCOMING FID_OUTGOING EQUI_INCOMING EQUI_OUTGOING
------------ ------------ ------------- -------------
       0            0             0             0

但是如果我从shell脚本调用SQL:

 sqlplus -s /@$TWO_TASK @${SQLDIR}/SWID_msgChecks.sql 1>${OUTPUT} 2>$1

列名不写入文件,如何将标题/列名写入文件?

由于

1 个答案:

答案 0 :(得分:1)

您不能从SQL * Plus中正确调用它,因为您已经禁用了列标题的SET HEADING OFFSET PAGESIZE 0

来自this reference document

HEA[DING] {OFF|ON}
   print column headings

PAGES[IZE] {14|n}
   The height of the page - number of lines.
   0 will suppress all headings, page breaks, titles

当您从shell脚本调用SQL * Plus时,您将获得您所指定的内容(即没有标题)。如果您希望标题保留,则应使用SET HEADING ON并将PAGESIZE设置为某个非零值。