我有以下sql:
select
CASE
WHEN Count(*) > 1
THEN 'Archiving task was executed succesfully!'
ELSE 'Archiving task was not executed succesfully for day: ' || Days
END CASE
from
(select substr(table_name,12,8) as Days from user_tables
where table_name like 'CDR_DETAIL_%' AND SubStr(table_name,12,8) IN ( SELECT * FROM tmp_archive_process_ict )
OR SubStr(table_name,12,8) IS null
order by 1 asc )
where rownum <= 7
GROUP BY Days
;
在sql工具中返回以下结果:
CASE
Archiving task was not executed succesfully for day: 20130819
Archiving task was executed succesfully!
Archiving task was not executed succesfully for day: 20130821
Archiving task was not executed succesfully for day: 20130820
在shell中使用sqlplus,我试图将之前显示的sql的结果返回到文件中:
unix shell的一部分:
#Make oracle conneciton
-oracle connection sqlplus
SET PAGESIZE 0;
SET ECHO OFF;
SET SPACE 0;
SET FEEDBACK OFF;
SET HEADING OFF;
SPOOL /bmd/mail_check.txt
select
CASE
WHEN Count(*) > 1
THEN 'Archiving task was executed succesfully!'
ELSE 'Archiving task was not executed succesfully for day: ' || Days
END CASE
from
(select substr(table_name,12,8) as Days from user_tables
where table_name like 'CDR_DETAIL_%' AND SubStr(table_name,12,8) IN ( SELECT * FROM tmp_archive_process_ict )
OR SubStr(table_name,12,8) IS null
order by 1 asc )
where rownum <= 7
GROUP BY Days
;
SPOOL OFF;
EXIT;
EOF
脚本有效,它会生成文件但是当我检查文件时(cat /bmd/mail_check.txt)它只显示我:
Archiving task was executed succesfully!
我不明白为什么它没有显示我从sql select到指定文件的其他结果。:
Archiving task was not executed succesfully for day: 20130819
Archiving task was not executed succesfully for day: 20130821
Archiving task was not executed succesfully for day: 20130820
我做错了什么?
提前谢谢你。
致以最诚挚的问候,