Looking at data can get tedious. Your eyes start to hurt. Your mind starts to wander. You start humming the theme song to The A-Team. Wouldn’t it be nice if the data you started your day with could be jazzed up a bit?
We’ve seen in an earlier post how you can use gauges and hyperlinks in your queries and grids. But maybe you didn’t realize that just plain jane HTML tags would also work.
Yes folks, you can get Comic Sans MS in your grids.
Here’s an example:
SELECT
CASE
WHEN E.Salary >5000
THEN '<html><strong><font color="red" face="Comic Sans MS" size=5>'
||E.first_name
||'</font></strong>'
ELSE '<html><font color="blue">'
||E.first_name
||'</font>'
END First_Name,
last_name, '<html><font color="green" size =3>' || salary ||'</font></html>' SALARY
FROM
hr.employees e;
Running this in a SQL Developer worksheet with F9 or ctrl+enter will produce output that looks like this:
So what else can it render? Let’s find out!
select '<HTML><li>My Data</li></html>' MoreFunStuff from dual union select '<HTML><img src="http://www.wvu.edu/images/wvu.png" height=23 width=134></HTML>' MoreFunStuff from dual union select '<HTML><table cols="3" border=2><th>Tables</th><th>Inside of</th><th>Tables</th></table></HTML>' MoreFunStuff from dual;
What’s This Really Good For Though?
This might fall more on the trick side of the tip vs trick scale. But, if you get creative with reports like @ba6dotus has done here with a Log Switch Frequency Map, then I think you might see some true potential with this.
Don’t Forget to Permanently Save These For Later
After you’ve built a few of these, save them as Snippets. Select the code, right click, ‘Save as Snippet…’ Use the ‘Custom’ category, then you can recall them on demand and not have to worry about pulling them from your SQL History list.



Twitter
RSS
GooglePlus
Facebook
Jul 25, 2012 @ 12:04:34
It’s a very nice feature! Colors are a very nice addition for emphasizing specific data.
It would be really great if when exporting to HTML, EXCEL would keep the colors.
Jul 25, 2012 @ 13:36:25
In previous comment I was referring to HTML in general not only to colors, but I must say that the colors stuck to my mind
Jul 25, 2012 @ 14:22:08
Didn’t know this is also possible. Nice playing with colors
Thanks for info.
Regards,
Marko
Jul 25, 2012 @ 14:45:36
I should have known after experimenting with the hyperlinks to the object tree, but @krisrice had to remind me.
Jul 31, 2012 @ 04:58:07
Is there a way to automatically adjust the column width when a column is formated with html?
It seesm that SQL Developer adjusts the width not only to the data, but also to the html markup, which makes the column much wider than necessary.
Thank’s for the cool tip.
Jul 31, 2012 @ 08:45:56
I noticed that as well. For the screenshots, I used the column header context menu ‘Auto-fit All Columns – On Data’