File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes [SQL] varchar2 to number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "[SQL] varchar2 to number" Watch "[SQL] varchar2 to number" New topic

[SQL] varchar2 to number

Michael Houlo
Ranch Hand

Joined: Jun 07, 2010
Posts: 58
Hello guys,

In one of my tables, i have a varchar2 column.
This column contains numbers and null values . (hm yeah..)

I'm trying to compare this field with some constant such as "column > 50".
I tryed this :

I even tryed to merge it with trim,nvl & to_char functions but i still can't get a good result..

ps= Nombre non valide = unvalid number.. :P
Stephan Mueller
Ranch Hand

Joined: May 05, 2010
Posts: 50
The number-pattern you are using is invalid, or to be correct, is invalid for your use-case as such that
it doesn't reflect the pattern of the actual values.
Assuming that you are using Oracle (be aware that this is not covered by the SQL standard afaik),
please have a look at
on how to correctly use the to_number function.

1. Make it run - 2. Make it run correctly - 3. Make it pretty OR fast/small - 4. ??? - 5. Profit
Michael Houlo
Ranch Hand

Joined: Jun 07, 2010
Posts: 58
I had to use
to_number(field,'99.999999999','NLS_NUMERIC_CHARACTERS=''. ''')
together with a TRIM..

Thanks anyway
I agree. Here's the link:
subject: [SQL] varchar2 to number
jQuery in Action, 3rd edition