我是SQL新手,我尝试运行查询以使用某些条件从数据库中提取警报,并将结果输出为csv格式的文件。
我创建了下面的SQL脚本,但是标题不是以所需的格式生成的。
set markup HTML on ENTMAP on spool off PREFORMAT on;
set pagesize 0 embedded on;
set feedback off;
set termout off;
set trimout on;
spool on;
set trimspool on;
spool /tmp/scripts/outputFiles/calExport.csv REPLACE;
select (y.ALARM_DN||','||x.CO_NAME||','||to_char(y.ALARM_TIME, 'dd-MM-yyyy HH24:MI:SS')||','||y.ALARM_TEXT||','||y.ALARM_TYPE||','||y.PERCEIVED_SEVERITY||','||y.ADDITIONAL_INFO_1||','||y.ADDITIONAL_INFO_3||','||y.ADDITIONAL_INFO_2) from CTP_COMMON_OBJECTS x, FM_ALARM y where y.NE_GID=x.CO_GID and y.ALARM_STATUS=1;
spool off;
exit;
当前输出: '
' (Y.ALARM_DN||','||X.CO_NAME||','||TO_CHAR(Y.ALARM_TIME,'DD-MM-YYYYHH24:MI:SS')|| -------------------------------------------------------------------------------- xxxx/xxxx-143/xxxx-143,xxxxxxxxxxxxxxxxxxxx,xxxxxxxxxxxxxx ,03-10-2017 15:19:49,Dead Peer Detected,1,2,shared:N;,,additionalFaultId:0;xxxx/xxxx-143/xxxx-143,xxxxxxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxxx,13-09- 2017 12:45:48,LOS on unit 0, Ethernet interface 4,1,1,,,
xxxx/xxxx-143/xxxx-143,xxxxxxxxxxxxxxxxxxxx,03-10-2017 15:19:39,BA NOTIFICATION,3,3,Files collected,,100 100 100 6450xxxx 1 0 path=/xxxx-1(Left) additionalFaultId:6450;
问题:
如何更正标题格式以匹配以下内容?
ALARM_DN,NAME,ALARM_TIME,TEXT,TYPE,SEVERITY,A,B,C
如何删除" pre"标记在输出文件的开头和结尾?
感谢您的帮助。
BR,
A.M。
答案 0 :(得分:1)
要将标题更改为您想要的SQL * Plus脚本,请将其更改为:
set markup HTML on ENTMAP on spool off PREFORMAT on;
set pagesize 0 embedded on;
set feedback off;
set termout off;
set trimout on;
SET HEADING OFF;
spool on;
set trimspool on;
spool /tmp/scripts/outputFiles/calExport.csv REPLACE;
SELECT 'ALARM_DN,NAME,ALARM_TIME,TEXT,TYPE,SEVERITY,A,B,C' FROM DUAL
UNION ALL
select (y.ALARM_DN||','||x.CO_NAME||','||to_char(y.ALARM_TIME, 'dd-MM-yyyy HH24:MI:SS')||','||y.ALARM_TEXT||','||y.ALARM_TYPE||','||y.PERCEIVED_SEVERITY||','||y.ADDITIONAL_INFO_1||','||y.ADDITIONAL_INFO_3||','||y.ADDITIONAL_INFO_2) from CTP_COMMON_OBJECTS x, FM_ALARM y where y.NE_GID=x.CO_GID and y.ALARM_STATUS=1;
spool off;
exit;
祝你好运。