Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle varchar to number

How do i convert a oracle varchar value to number

eg

table - exception exception_value 555 where exception_value is a varchar type 

I would like to test the value of exception_value column

select * from exception where exception_value = 105 instead of select * from exception where exception_value = '105' 
like image 771
user141511 Avatar asked Jul 20 '09 16:07

user141511


People also ask

How do I convert varchar to numeric in SQL?

To convert a varchar type to a numeric type, change the target type as numeric or BIGNUMERIC as shown in the example below: SELECT CAST('344' AS NUMERIC) AS NUMERIC; SELECT CAST('344' AS BIGNUMERIC) AS big_numeric; The queries above should return the specified value converted to numeric and big numeric.

Can VARCHAR2 store numbers?

The biggest reason is that when stored in a VARCHAR2 datatype, you can retain your leading zeros, whereas in a NUMBER datatype, you cannot. For instance, many zip codes on the east coast start with a zero.

What is TO_NUMBER in SQL?

The TO_NUMBER function converts its argument to a DECIMAL data type. The argument can be the character string representation of a number or a numeric expression.


2 Answers

You have to use the TO_NUMBER function:

select * from exception where exception_value = to_number('105') 
like image 156
FerranB Avatar answered Oct 14 '22 01:10

FerranB


Since the column is of type VARCHAR, you should convert the input parameter to a string rather than converting the column value to a number:

select * from exception where exception_value = to_char(105); 
like image 23
Tony Andrews Avatar answered Oct 13 '22 23:10

Tony Andrews