All Forums General
kparadise 4 posts Joined 02/16
09 May 2016
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)"?

kparadise 4 posts Joined 02/16
09 May 2016

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

yuvaevergreen 93 posts Joined 07/09
10 May 2016

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

You must sign in to leave a comment.