I am facing some difficulties for a Datawarehouse transformation task, I have some source columns which are coming in varchar format, data contained: Blanks, -, decimal numbers such as (1234.44).
Those columns in target are declared as number.
I am trying to treat that data with this code but I keep receiving invalid number error:
CASE WHEN
LENGTH(TRIM(TRANSLATE(column78input, '-', ' '))) is null then null
WHEN column78input IS NULL THEN 0
else to_number(column78input)
END
In first when statement I am trying to check if there is - in source, it returns null when found, and if you find it then place it as null (replacing dashes with nulls in essence)
In second when statements I am trying to treat those blanks, I thought that they might cause the error
And finally in else statement I want to parse it from varchar to number to load in target table.
If someone has some kind of suggestion, please help!
Thanks
Try with
CASE
WHEN INSTR(column78input, '-') > 0 OR column78input IS NULL THEN 0
ELSE TO_NUMBER(REPLACE(column78input, ' '))
END
INSTR returns the first position of a character in a string. So if there is no dash, it would return 0. A value greater than 0 means there is at least one dash in the string.
Here are a few mistakes in your code :
column78input IS NULL