Convert Text to Number

General
Enthusiast

Convert Text to Number

I have a field in a table which is labeled a "VARCHAR(4500)"; which contains a number, but it is written in text. 

I want to convert this field to a dollar amount, so I can compare it to other dollar fields. 

Is there a simple was to convert "VARCHAR(450)" to "DECIMAL(10,0)"?

2 REPLIES
Enthusiast

Re: Convert Text to Number

Is it as simple as CAST(col AS INTEGER) ?

Enthusiast

Re: Convert Text to Number

If you are sure about the numeric value, then cast(col as decimal(9,1))
IF you are unsure about the numeric value, then
case
when to_number(col) is not null
then cast(col as decimal(9,1))
else 0
end