aspose file tools
The moose likes JDBC and the fly likes to_number function question. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "to_number function question." Watch "to_number function question." New topic
Author

to_number function question.

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
I have a sql query which converts my varchar to a number. Whenever there is a field which contains non numerical values. the query returns an error. Is there some way to return null if the field contains non-numerical data, and a number if the field contains numerical data?

my query: "select to_number(col_1) from tbl_a"
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26496
    
  78

Fritz,
To do that in a non-database specific way, you can use a union:


In some databases, like Oracle, you can use a function for the conditional.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: to_number function question.
 
Similar Threads
To_number function not work with decode function.
Instant DB , to_number function
B&S: Customer ID (owner) exact 8 digits or not?
How to create table dynamically in JDBC?
[SQL] varchar2 to number