Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a command to format display column width

Status
Not open for further replies.

swaroop

Programmer
Feb 4, 2001
100
0
0
US
Please help me, I am typing a Sql command on a database table
Code:
Select * form SoSo..
The display come up zigzag on my sqlplus screen because of uneven size of columns in the table(there are 5 columns). I wanted to display all columns with certain width. I want a sql command for that.

Thanks in advance.

Swaroop Kunduru.
 
Swaroop,

If you want a SQL command to format the columns, then the best ones are probably a SUBSTR function (for VARCHAR data) and TO_CHAR function (for NUMBER data):
Code:
select substr(last_name,1,10)"Last Name"
      ,substr(first_name,1,10)"First Name"
      ,TO_CHAR(salary,'999,999.99')"Salary"
from s_emp;

Last Name  First Name Salary
---------- ---------- -----------
Velasquez  Carmen        3,327.50
Ngao       LaDoris       1,450.00
Nagayama   Midori        1,400.00
Quick-To-S Mark          1,450.00
Ropeburn   Audry         1,550.00
If you are using SQL*Plus, then you can use its native display-formatting capabilities:
Code:
col a heading "Last Name" format a10 trunc
col b like a heading "First Name" 
col c heading "Salary" format 999,999.99
select last_name a, first_name b, salary c
from s_emp;

Last Name  First Name      Salary
---------- ---------- -----------
Velasquez  Carmen        3,327.50
Ngao       LaDoris       1,450.00
Nagayama   Midori        1,400.00
Quick-To-S Mark          1,450.00
Ropeburn   Audry         1,550.00
Let us know if this information is what you wanted.


[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I can provide you with low-cost, remote Database Administration services: see our website and contact me via www.dasages.com]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top