首页 > 解决方案 > SQL 查询中的 HTML

问题描述

--select the data to highlight using html in sql queries
select
id_c,
salary_c,
case 
when salary_c > 50000 then '<html><bgcolor=yellow><font color=red size=5><b>'||to_char(salary_c)||'<html>'
else to_char(salary_c)
END as conditionalsalary
from employees;

请让我知道我在哪里做错了。我正在使用 oracle 11g 和 dbeaver 客户端工具。我想要使​​用 SQL 查询中的 html 标记以红色大小 5 和背景颜色黄色显示的条件列高亮的结果超过 50000...

在此处输入图像描述

标签: sqloracleplsqloracle-sqldeveloper

解决方案


您正在使用能够呈现 HTML 的 SQL Developer,请参阅https://www.thatjeffsmith.com/archive/2012/07/using-html-to-mark-up-your-data-in-oracle-sql-开发商/

您的 HTML 不正确,您缺少结束标签、引号,并且bgcolor据我所知不是有效标签。大概应该是:

select
id_c,
salary_c,
case 
when salary_c > 50000 then '<html><font color="red" size=5 style=“background-color:yellow;"><b>'||to_char(salary_c)||'</font></html>'
else to_char(salary_c)
END as conditionalsalary
from employees;

推荐阅读