sqlplus HTML 标记输出

sqlplus HTML markup output

我是运行一个调用sqlplus脚本的win bat脚本,然后通过电子邮件发送sqlplus脚本的输出,这是我的脚本

ttitle left 'Last Successful Run for Oracle or Siebel'
break on cntry skip 1;
set pages 100;
select lpad(country,6,' ') cntry, max(timestamp) Timestamp,substr(LPAD(test_type,10,' '),0,10) Type,
CASE
        WHEN ((sysdate-max(timestamp))*1440) >=60 THEN '<===== ERROR over 60 minutes since last run'
        WHEN ((sysdate-max(timestamp))*1440) >=30 THEN  '<===== WARNING over 30 minutes since last run'
        ELSE ''
    end as  status
from rfgdba.perf_test_results ptr, rfgdba.perf_tests pt
where country is not null and test_id in ((select id from rfgdba.perf_tests where live='Y')) and test_type in ('ORACLE','SIEBEL') 
and timestamp > sysdate-30 and ptr.test_id=pt.ID
group by country, test_type
order by country, timestamp ;

输出为 table 格式,但我想在 CASE 部分周围添加颜色编码,即如果值 >60 则将 txt 背景着色为红色,如果值 >30<60 则 txt背景橙色,如果值 <30,则 txt 背景为绿色,但我无法让它工作,我尝试了以下方法

CASE
        WHEN ((sysdate-max(timestamp))*1440) >=60 THEN '<tr style="color:red'||'<===== ERROR over 60 minutes since last run'||'"></tr>'
        WHEN ((sysdate-max(timestamp))*1440) >=30 THEN '<tr style="color:orange'||'<===== WARNING over 30 minutes since last run'||'"></tr>'
        ELSE <tr style="color:green'||''||'"></tr>'
    end as  status

但是报错

错误: ORA-01756: 带引号的字符串未正确终止

所以我很难过:(

那是因为您的 else 语句在 <tr> 之前没有引号。

现在我的 sql 完成了,输出看起来像这样

Last Successful Run for Oracle or Siebel         
CNTRY   TIMESTAMP   TYPE    STATUS
at  08-20-2015 12:51:45     SIEBEL  <tr style="color:red<===== ERROR over 60 minutes since last run"></tr>
    08-20-2015 13:48:21     ORACLE  <tr style="color:green"></tr>
be  08-20-2015 13:46:53     ORACLE  <tr style="color:green"></tr> 
    08-20-2015 13:51:28     SIEBEL  <tr style="color:green"></tr>