Sqlplus is my second home: Part 6 – Colorizing sqlplus and terminal output

Tanel Poder


Jagjeet Singh mentioned that he has built a V2 of his cool SQL Dashboard sqlplus-based monitoring script, which now also shows a nice colored ASH graph output. Yes, right inside sqlplus!

This reminded me that I demoed color output in sqlplus when I delivered the Hotsos Symposium training day a few years ago, when introducing the MOATS tool the first time. I never got to colorize it as I had hoped to though… as MOATS was more of a fun project I worked on with Adrian Billington just to prove that it is possible to build a monitoring tool purely based on SQL and PL/SQL with a TOP-like self-refreshing screen output.

Anyway, Jagjeet has done this cool work now, but if you want to colorize some of your own scripts, then on XTerm-capable terminal emulators its simply done with just outputting some escape codes before the text you want to color. Most (or even all) widely used XTerm clients support 8 colors for text and 8 for background – but some terminal emulators (like putty, iTerm, Terminator) even support 256 colors!

Here’s a simple example script I demoed at the Hotsos training day too:

Just run it in sqlplus and see what happens! Note that you have to use the sqlplus in an XTerm terminal emulator (maybe ANSI terminals would work too) – this won’t work in Windows Command prompt!

Anyway, have fun and keep those cool & colorful sqlplus scripts coming! :-)