LuckyLucks
asked on
Formatting varchar to numeric
Hi EEE
I'd like to change the varchar columns to number in my returned SQL in Oracle. How to? Tried
Select blah format s3
from myTable
I'd like to change the varchar columns to number in my returned SQL in Oracle. How to? Tried
Select blah format s3
from myTable
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Trying to do this: "change the varchar [values] to number in my returned SQL in Oracle" will usually result in this error:
ORA-01722: invalid number
Because, usually data that is in a VARCHAR2 column in Oracle is not all valid numbers, or is not all formatted consistently enough to automatically convert it to a NUMBER datatype. You will usually need something like the suggestion from Geert Gruwez to identify the records with "bad" values first. (I'm not an expert with "regular expressions" like what he suggested, but they can be handy. I usually have to use a PL\SQL function with a "to_number" conversion and an exception section.) Then, if you manually update any records with non-numeric data to valid, numeric values first, you should be able to run your query with TO_NUMBER.
ORA-01722: invalid number
Because, usually data that is in a VARCHAR2 column in Oracle is not all valid numbers, or is not all formatted consistently enough to automatically convert it to a NUMBER datatype. You will usually need something like the suggestion from Geert Gruwez to identify the records with "bad" values first. (I'm not an expert with "regular expressions" like what he suggested, but they can be handy. I usually have to use a PL\SQL function with a "to_number" conversion and an exception section.) Then, if you manually update any records with non-numeric data to valid, numeric values first, you should be able to run your query with TO_NUMBER.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
awking ... that doesn't change the column type
ASKER
thanks
select * from table
where not regexp_like(column, '\d')