Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: numbers in varchar2 field

Re: numbers in varchar2 field

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Fri, 09 Jun 2006 07:22:36 +0200
Message-ID: <p81i82dhobu9lsqc1eqej09oac2vmeqn9d@4ax.com>


On 8 Jun 2006 20:56:07 -0700, hinerman_at_gmail.com wrote:

>I have a table with a varchar2(25) field. Most of the data in there is
>a 9 digit number, while a few records have 4 digit numbers. I have it
>as a varchar2 field to allow for some instances of leading zeros. My
>problem is that the 4 digit numbers aren't behaving like strings. If I
>query the table like where fieldName = '4231', it doesn't return any
>results. But if I query where fieldName = 4231, without the quotes, it
>returns results. Is there some reason these records are being handled
>differently?

In the second case you are implicitly using to_number(fieldname) = 4231.
If your data is stored as ' 4231', it is only natural the first select fails.
You are ending up in a mess, and should convert the column to a number(n) asap. Leading zeroes is a *display* issue.

--
Sybrand Bakker, Senior Oracle DBA
Received on Fri Jun 09 2006 - 00:22:36 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US