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'
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.
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.
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.
You have to use the TO_NUMBER function:
select * from exception where exception_value = to_number('105')
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With