我有一个运行SQL*Plus命令的批处理脚本,并且我正在将输出假脱机到CSV文件。所有输出只有一列"count“。有没有办法将文本添加到结果中?
"The_current_valueOf Query1" "Count1"
"The_current_valueOf Query2" "Count2"任何帮助/建议都将不胜感激。
set colsep ,
set pagesize 0
set trimspool on
set headsep off
set Newpage none
spool D:\TRHMIBS\TRH\TRHStats.csv
select count(*) from host.ufm where insert_time between trunc(sysdate) and sysdate
/
spool D:\TRHMIBS\TRH\TRHStats.csv APPEND
select count(*) from host.amendment where insert_time between trunc(sysdate) and sysdate and msg_source = 'AUDIT'
/
spool D:\TRHMIBS\TRH\TRHStats.csv APPEND
select count(*) from host.ufm_amendment where insert_time between trunc(sysdate) and sysdate and msg_source = 'DAS' and ext_token is null
/
spool off;
exit;发布于 2016-08-27 01:41:36
您可以只选择消息作为硬编码的文字。例如:
spool D:\TRHMIBS\TRH\TRHStats.csv
SELECT 'The_current_valueOf Query1:', COUNT(*)
FROM host.ufm
WHERE insert_time BETWEEN TRUNC(sysdate) AND sysdate
/发布于 2016-08-27 01:42:06
这与假脱机无关。您的第二个和第三个spool命令是多余的-所有内容都会假脱机到打开的文件中,直到您将其关闭。但这是一个次要问题。
您可以使用列表达式将另一列添加到输出中,列表达式可以是字符串文字。因此,您可以将第一个查询更改为:
select 'The_current_valueOf Query1', count(*)
from host.ufm
where insert_time between trunc(sysdate) and sysdate然后对其他两个查询执行相同的操作。
由于您希望将其设置为CSV,因此可以不使用colsep,只需在列中嵌入一个逗号,您可以使用连接来完成此操作:
select 'The_current_valueOf Query1,' || count(*)
from host.ufm
where insert_time between trunc(sysdate) and sysdate而且,您可以将它们合并在一起,而不是运行三个单独的查询;这不会节省处理时间,但意味着所有输出都在一起。
select 'The_current_valueOf Query1,' || count(*)
from host.ufm
where insert_time between trunc(sysdate) and sysdate
union all
select 'The_current_valueOf Query1,' || count(*)
from host.amendment
where insert_time between trunc(sysdate) and sysdate
union all
...https://stackoverflow.com/questions/39170021
复制相似问题