If you have seen a colored scripts like a fish from “Session Snapper v.4” by Tanel Poder or OraLatencyMap by Luca Canali, you may be also want to colorize your scripts.

I’ve created the script for this purposes with predefined substitution variables.

Just download colors.sql and use it like that:

@colors.sql; prompt ::: &_C_RED *** TEST PASSED *** &_C_RESET ::: prompt ::: &_C_RED *** &_C_BLINK TEST PASSED &_C_BLINK_OFF *** &_C_RESET :::

You’l get something like this:





List of variables Description Variable _C_RESET Reset formatting – Turn off all attributes _C_BOLD

_C_BOLD_OFF Set bright mode on/off _C_UNDERLINE

_C_UNDERLINE_OFF Set underline mode on/off _C_BLINK

_C_BLINK_OFF Set blink mode on/off _C_REVERSE

_C_REVERSE_OFF Exchange foreground and background colors _C_HIDE

_C_HIDE_OFF Hide text (foreground color would be the same as background) _C_BLACK

_C_RED

_C_GREEN

_C_YELLOW

_C_BLUE

_C_MAGENTA

_C_CYAN

_C_WHITE

_C_DEFAULT Font colors _CB_BLACK

_CB_RED

_CB_GREEN

_CB_YELLOW

_CB_BLUE

_CB_MAGENTA

_CB_CYAN

_CB_WHITE

_CB_DEFAULT Background colors [collapse]

Сolorless histogram -- loading colors variables: @inc/colors; -- set max length of bar: def _max_length=80; -- columns formatting: col bar format a&_max_length; -- clear screen: prompt &_CLS with t as (-- it's just a test values for example: select level id , round(dbms_random.value(1,100)) val from dual connect by level<=10 ) select t.* -- bar length is just " (value / max_value) * max_length" in symbols: ,floor( val * &_max_length / max(val)over() ) as bar_length -- generating of bar: ,lpad( chr(176) ,ceil(val * &_max_length / max(val)over()) ,chr(192) ) as bar from t; [collapse]

Colorized script -- loading colors variables: @inc/colors; -- set max length of bar: def _max_length=100; -- column formatting col bar format a&_max_length; -- clear screen: prompt &_CLS -- test query which prints histogram(or may be simply bars?): with t as (-- it's just a test values for example: select level id , round(dbms_random.value(1,100)) val from dual connect by level<=10 ) select id ,val , case when pct >= 0.9 then '&_C_RED' when pct <= 0.4 then '&_C_GREEN' else '&_C_YELLOW' end -- string generation: ||lpad( chr(192) ,ceil(pct * &_max_length)-9 -- color - 5 chars and reset - 4 ,chr(192) ) ||'&_C_RESET' as bar from ( select t.* ,val / max(val)over() as pct -- as a percentage of max value: from t ) t2 / [collapse]

In addition, i want to show simple example of printing histograms.We can simple print histogram with query:And now we can colorize it: