0
--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;

Please let me know where I did the mistake. am using oracle 11g and dbeaver client tool is. I wanted result of conditionalsalary column high light in red color size 5 and background color yellow which are more than 50000 using html tags inside SQL query...

enter image description here

4
  • 2
    What is your question, exactly? The only thing "wrong" with your query is that <bgcolor> isn't a HTML element and the <font> element is an obsolete HTML element that you should not be using. That, and the fact that SQL should not be used to format or render values for display. Commented Dec 20, 2020 at 11:29
  • "Please let me know where i did the mistake." First, please let us know what result you were expecting so that we can understand what you consider to be a "mistake". Without knowing what you were trying to achieve it is difficult to answer the question. Commented Dec 20, 2020 at 11:34
  • You can see by the result, that the query is doing exactly what you asked for. Unless you point out what is wrong, nobody can help you. Commented Dec 20, 2020 at 13:04
  • I improved the question above. kindly check it once again... Commented Dec 20, 2020 at 16:23

1 Answer 1

2

You’re using SQL Developer which is able to render HTML, see https://www.thatjeffsmith.com/archive/2012/07/using-html-to-mark-up-your-data-in-oracle-sql-developer/

Your HTML is not right, you are missing closing tags, quotes and bgcolor is not a valid tag as far as I can see. It probably should be:

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;
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot Andrew! But this is also returning similar results with tags in the data instead of just highlighting it.
Which SQL Developer version do you use, Rupasa? Because, values are nicely highlighted in my 19.4.
dbeaver tool am using it.
DBeaver doesn’t seem to have functionality to render html inside a result. If you want to do that you should just use SQL Developer which is equipped for this requirement. Otherwise you could take your results and export them to a html file then open them in a browser - obviously you might need to do some extra work to tidy things up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.