ORA-01722: invalid number Error in lpad
128269Mar 16 2005 — edited Mar 20 2005I get an ORA-01722 error on the following update statement when field1 contains a non-numeric character. The field is defined as CHAR(4). 99.99% of the time field1 will contain spaces and/or numeric data.
set field1 = lpad(to_char(to_number(field1)),4,'0')
where (substr (field1, 1, 1) = ' ' or
substr (field1, 4, 1) = ' ')
If I remove the to_number portion of the lpad statement I still get the ORA-01722 error. (This baffles me, to be honest.)
If I remove both the to_char and the to_number so that I just have the lpad statement, the field is not being padded with zeros, as per the following code example.
set field1 = lpad(field1,4,'0')
where (substr (field1, 1, 1) = ' ' or
substr (field1, 4, 1) = ' ')
First, I don't understand why the stand-alone lpad statement will not pad field1 with zeros.
Second, since the stand-along lpad isn't padding the fields, what can I do to make the set statement work to avoid the ORA-01722 error when non-numeric characters are present?
Thank you.