Question

I have this code in my procedure:

IF old_value_l = new_value_l THEN 
      dummy_val_l := 0;

    ELSIF old_value_l != new_value_l THEN   -- This is line 4019 mentioned in the error
         -- some code here

END IF;

But it is throwing some strange errors:

ORA-01722: invalid number
ORA-06512: at "DBS.MONITORING", line 4019
ORA-06512: at line 12

It clearly says that the number is invalid, but wait a minute, what number? Both old_value_l and new_value_l are declared as VARCHAR2(255 CHAR)

and here is how:

  new_value_l               history.new_value%TYPE;
  old_value_l               history.old_value%TYPE;

Why even when both of the variables are declared as VARCHAR2 it says that the number is invalid?

I know that I'm missing an extremely small part here, but I can't spot it or understand my mistake at this momment.

EDIT

Values I'm comparing:

new_value_l = 15 and old_value_l = 10

Was it helpful?

Solution

Code like this does not tell us they are numbers, it tells that first variable has a type like column new_value in history table, and the second variable has a type like old_value in history table.

new_value_l               history.new_value%TYPE;
old_value_l               history.old_value%TYPE;

So, you need to:

  1. Ensure that both of these columns have the same datatype, VARCHAR2
  2. Sometimes errors appear in a line, while actual error is in next or previous line, so you have to check them too
  3. Try to check there is no spaces stored in values by using trim

    ... 
    ELSIF trim(old_value_l) != trim(new_value_l) 
    ...
    
  4. I think you have to handle null values too.

    ... 
    ELSIF trim(old_value_l) != trim(new_value_l) 
    ...
    

OTHER TIPS

It will be converted to a number automatically. So, you can test it as per the below:

select 1 from dual where '114' >120;
select 1 from dual where '125' >120;

You'd better check whether each value has some characters which cannot be converted to a number, such as CRLF.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top