Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Number to Char conversion
On 9 Feb 1999 05:02:11 GMT, gennick_at_worldnet.att.net (Jonathan
Gennick) wrote:
>On 7 Feb 1999 18:05:24 +0100, mattias.meyer_at_t-online.de
>(mme) wrote:
>
>>When I do the following in PL/SQL:
>>
>><string> := TO_CHAR(<number>, '00');
><snip>
>>Why do I always get a errormessage saying the the conversion canīt be done?
>>When I declare the <string> as a CHAR(3) it works... but I get a
>>space/blank
>>as first position of the string. How come?
>
>Oracle is leaving one space for a leading sign. Convert a
>negative number, and you will see a "-" character in that
>position. Positive numbers get a space. This is by design.
>As you have already figured out, you must use LTRIM to
>eliminate that leading space.
>
>regards,
>
>Jonathan
>----------------------------------------------
>Jonathan Gennick -- Oracle DBA, Author, Editor
>jonathan_at_gennick.com
>http://gennick.com
>Brighten the corner where you are.
>
>>
>>I then use
>>LTRIM(<string>, ' ');
>>but I wanna know why it works the way it does????
>>
>>Regards
Alternatively,
<string> := to_char(<number>, 'FM00');
will format without the leading space.
Straight from Chap. 3 of Oracle PL/SQL Programming. The FM format modifier is listed as returning a value with no leading or trailing blanks.