I am using DB2 for IBM i V6R1, and I am trying to convert a string value which sometimes has a valid representation of a number in it into a number. What I came up with was this:
select onorno, onivrf, coalesce(cast(substr(onivrf,1,5) as numeric),99999) as fred
from oinvol
sometimes the ONIVRF field has data like '00111-11', sometimes it has data like 'FREIGHT'.
The documentation leads me to believe that for data like this:
ONORNO ONIVRF
12 11010-11
13 FREIGHT
14 00125-22
I should get output like this:
ONORNO ONIVRF FRED
12 11010-11 11010
13 FREIGHT 99999
14 00125-22 125
instead, I am getting this:
ONORNO ONIVRF FRED
12 11010-11 11010
13 FREIGHT NULL
14 00125-22 125
(If I skip the coalesce() and just use the Cast(substr(onivrf(1,5) as numeric), I get exactly the same results.)
What am I doing wrong here?
null, I'm getting the 'replacement character' (which is+- null is indicated with a-). There's also other behaviour related to this (IS NULLdoesn't work, for example) that leads me to believe that I'm getting back what amounts to aNaNresult for the operation... somehow. - Clockwork-Muse