Click here to Skip to main content
15,889,867 members
Articles / Programming Languages / SQL
Tip/Trick

Displaying a Bar Chart using SELECT command in Oracle

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
4 Aug 2012CPOL1 min read 12.5K   3  
This tip demonstrates using the Select command to display a bar chart.

Introduction

This is a short tip about how you can display a bar chart using a simple select command in Oracle.

Background

It is said that a picture is worth a thousand words. Charts help you to visualize data quickly and are a compact way to present information. Also charts are more appealing to the mind than figures.

Using the code

We shall be using the LPAD function of Oracle to produce our chart. The LPAD function has the following syntax:

LPAD(string,pad_length,[pad_string])  

The parameters of LPAD function are as follows:

  • string: Represents the string to be padded
  • pad_length: Specifies the length after padding.
  • pad_string: It is an optional string which is used to fill the left side of the string. If omitted, LPAD fills the left side with spaces.

The following statement can be used to produce the chart.

C++
select lpad(ename,10) || lpad(chr(220),sal / 100,chr(220)) || ' ' || sal
as "Employee Salary"
from emp
/

In the above statement, I am displaying the salary of employees from the sample table "emp". I am using the character 220 (chr(220)), to display the bars. The salary is scaled down to printable range by dividing it by 100.

Following is the output of the above select statement.

Image 1

Points of Interest

You can experiment the select command with different characters to create charts with different patterns.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer NIIT, India
India India
I am a trainer by profession. Currently I am working with iFuture Technologies(India) as a Senior Faculty. I enjoy programming as a hobby. During my career I have seen the growth and decline of many technologies, many of them being my favorites like Flash, WPF, Windows Mobile Development. Few of my current favorites are Android, Xamarin and Python, though I also like traditional and evergreen languages like PHP, C#, Visual Basic and Java.

Apart from computers, my favorite pastime is bicycling.

Comments and Discussions

 
-- There are no messages in this forum --