Data Conversion

UDA
Enthusiast

Data Conversion

Hi

Can you please help me convert char(16) to decimal(18,0)
e.g. select Cast(OAA_N as decimal (18,0) ) O_Account_Num from Account

Error: It says bad character formatting.
7 REPLIES
Enthusiast

Re: Data Conversion

Your statement is syntactically correct. Evidently, the source column data does not parse correctly as a decimal string.
Enthusiast

Re: Data Conversion

Can u please provide some sample data.
Enthusiast

Re: Data Conversion

It should be a problem with your source data..the select statement you have given is correct..can you provide some sample data?

Re: Data Conversion

Hi,

Actually your trying to convert from character to decimal, which is not possible. Since, decimal data type will not accept characters.....

You can convert Numeric column to characters, but not from character to numeric or decimal.
Junior Contributor

Re: Data Conversion

Hi Raghu,
since the very early days of SQL it is possible to CAST a string to a numeric value, why do you think it's not allowed?

Dieter

Re: Data Conversion

Hi Dieter,

Please solve above problem.. please.

Regards,

Poonam

Re: Data Conversion

If the value of the column is a valid number but stored as Character, then you can CAST it as DECIMAL.

But in your case, the column values seem to be alphabets or alphanumeric.

Check the column values, if all the values are numbers, then you should be able to cast it to DECIMAL.