Graphic In Text Mode

I have to admit that I am a fanatic of the text mode, began to play computers in the eighties and practically everything was text mode. Today I will show a very simple function to put a kind of graphic (in text mode) to get our querys a little more interesting.

Here is the code;

-------------------------------------------------------------------------------- 
--Function that generate a graphic for percentages in text mode
--The function have five parametero, first one mandatory and the rest
--are optionals.
--
-- Parameter list;
--
-- Position 1 Is the figure that represent the percentage
-- Position 2 Is how many characters are used for generate the graph text (10)
-- Position 3 Is the simbol used for represent the percent (*)
-- Position 4 Is the simbol used for represent the space until the end ( )
-- Position 5 Is a flag to show the last string (number plus % simbol) (TRUE)
-- 
-- --- example i ----
-- SELECT PERCENTAGE_GRAPH_TEXT (20) FROM DUAL;
--
-- Result: [**........] 20%
--
-- -- example ii -----
-- SELECT PERCENTAGE_GRAPH_TEXT (20, 5, '=', ' ') from dual;
--
-- Result: [=    ] 20%
--
--
--  AUTOR:   Antonio NAVARRO
--  FECHA:   28.10.99
--  MODIFICADO: 28.10.99
--  FICHERO: PERCENTAGE_GRAPH_TEXT.SQL
--  LOCALIZACION: \\SAN/NAS
--
---------------------------------------------------------------------------------

CREATE OR REPLACE
FUNCTION PERCENTAGE_GRAPH_TEXT
(
numero number ,
longitud number default 10 ,
simbolo varchar2 default '*' ,
simbolo_relleno varchar2 default '.' ,
numero_por_centaje boolean default true
) RETURN VARCHAR2 IS

TEXTO VARCHAR2(110);

BEGIN


-- Open textgraph ---
TEXTO := TEXTO || '[';

FOR i IN 1..longitud LOOP
/*** Si estamos en porcentaje escribir simbolo, sino escribir vacio ***/
IF round ((i*100)/longitud) <= numero THEN
TEXTO := TEXTO || simbolo;
ELSE
TEXTO := TEXTO || simbolo_relleno;
END IF;

END LOOP;

-- Close texgraph ---
TEXTO := TEXTO || ']';

IF numero_por_centaje THEN
TEXTO := TEXTO || ' ' || numero || '%';
END IF;

RETURN (TEXTO);


END; /*** PERCENTAGE_GRAPH_TEXT ***/
/

An example of this will be like show below;

WEB*ANTO> SELECT PERCENTAGE_GRAPH_TEXT (20) FROM DUAL;

PERCENTAGE_GRAPH_TEXT(20)
_______________________________________________________________________
[**……..] 20%

WEB*ANTO> SELECT PERCENTAGE_GRAPH_TEXT (20, 5, ‘=’, ‘ ‘) from dual;

PERCENTAGE_GRAPH_TEXT(20,5,’=’,”)
_______________________________________________________________________
[= ] 20%

There are many options and possibilities that are left for the reader.

HTH – Antonio NAVARRO

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s