views:

45

answers:

2

Hi guys I'm using varchar2 for a product name field, but when I query the database from the run SQL command line it shows too many empty spaces, how can I fix this without changing the datatype

here is the link to the ss

http://img203.imageshack.us/img203/20/varchar.jpg

+1  A: 

The data that got inserted into the database (probably through some ETL process) had spaces which were not trimmed.

You could update using (pseudo code)

Update Table Set Column = Trim(Column)
Raj Kaimal
whats an etl process?
DAVID
i inserted it through the command line
DAVID
i did this but it didnt help, its the same
DAVID
A: 

If TRIM does not change the results, that tells you that there are not trailing spaces in the actual database rows; they're just being added as part of the formatted screen output.

By default, sqlplus (the command-line Oracle tool you appear to be using) uses the maximum length of the varchar2 column as the (fixed) width when displaying the results of a select statement.

If you want to change this, use the column format sqlplus command before running the select. For example:

column DEPT_NAME format a20
David Gelhar