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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why extra space in to_char conversion? 3

Status
Not open for further replies.

nagornyi

MIS
Nov 19, 2003
882
US
The query

select to_char(rownum, '00') from all_tables where rownum<21

adds extra space in front of each item. Why?
 
Nagornyi,

The "extra" space on the left of any number-to-character conversion in Oracle is the "sign byte" to accommodate the minus sign in case the numeric value goes negative.

If you wish to get rid of the "extra" space, you can modify your code to read:
Code:
select substr(to_char(rownum, '00'),-2) from all_tables where rownum<21;

SU
--
01
02
03
.
.
.
20

Let us know if this resolves your question.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)

Do you use Oracle and live or work in Utah, USA?
Then click here to join Utah Oracle Users Group on Tek-Tips.
 
I actually did that substr already and just was wondering why extra space. OK, now I understand. Thanks!
 
Or, if you are lazy like I am, use:
Code:
ltrim(to_char(rownum),' ')

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Sr. App. Developer Analyst/Custom Forms & PL/SQL - Oracle/Windows
Author and Sole Proprietor of: Emu Products Plus
 
Use this better:
Code:
to_char(rownum, 'FM00')
[bigglasses]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
how come i donot get any extra space in the front when I ran it in toad?

-engi
 
Try
Code:
select length(to_char(rownum, '00')) from all_tables where rownum<2
What do you get? 2 or 3?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top