Oracle. Convert varchar value "40.00" to numerical

oracle, sql

Solution

You could convert the varchar to a decimal like:

select *
from YourTable
where CAST(YourField AS decimal) < 40.00

Or use the TO_NUMBER() function:

select *
from YourTable
where TO_NUMBER(YourField) < 40.00

If the field is not always a number, and you have a relatively recent Oracle installation, you can select rows where YourField is numeric like:

select *
from (
    select * 
    from YourTable
    where regexp_like(YourField, '^-?[[:digit:],.]+$')
) sub
where TO_NUMBER(YourField) < 40.00

Problem

For example, a have varchar value "40.00" and want to use it with operators ">" or "<" in where clause. How can I use it?

Original source