Phani Arya
Phani Arya

Reputation: 1

Getting ORA-06502: PL/SQL: numeric or value error: character to number conversion error in SQL trigger

I'm getting below error in the web methods adapter on the table which has the MIH_TRIGGER.

(65000/6502) ORA-06502: PL/SQL: numeric or value error: character to number conversion error ORA-06512: at "B2B_OPS_BUILD_ADMIN.MIH_TRIGGER", line 2 ORA-04088: error during execution of trigger 'B2B_OPS_BUILD_ADMIN.MIH_TRIGGER'

Below is the MIH_TRIGGER fore reference which will update the data from OPS_BUILD_MIH table to OPS_BUILD_AUDITLOG table whenever OFFSET column is updated.

The OFFSET column in OPS_BUILD_MIH is NUMBER

The OLD_VALUE and NEW_VALUE columns in OPS_BUILD_AUDITLOG are VARCHAR2(100).

I'm trying to insert a numeric value which is in OFFSET column into the OLD_VALUE and NEW_VALUE varchar2 columns and getting this error.

create or replace TRIGGER "B2B_OPS_BUILD_ADMIN"."MIH_TRIGGER" 
AFTER UPDATE OF OFFSET
ON OPS_BUILD_MIH
FOR EACH ROW
BEGIN
 if ( nvl(:OLD.OFFSET,'xYz#@!0') != nvl(:NEW.OFFSET,'xYz#@!0')) then
  INSERT INTO OPS_BUILD_AUDITLOG
    (TABLE_NAME,
     COLUMN_NAME,
     OLD_VALUE,
     NEW_VALUE,
     UPDATED_BY,
     UPDATED_DTM,
     UUID)
  VALUES  
    ('OPS_BUILD_MIH',
     'OFFSET',
     :OLD.OFFSET,
     :NEW.OFFSET,
     :NEW.LAST_UPDATED_BY,
     :NEW.LAST_UPDATED_DTM,
     :OLD.MIH_ID);
 end if;

END; 

Can you please suggest a fix for this so that I can modify the above trigger accordingly.

Appreciate your help in advance.

Regards Phani

Upvotes: 0

Views: 1404

Answers (1)

Boneist
Boneist

Reputation: 23588

As Gaj has already pointed out, the issue lies with your NVL - you're trying to compare a non-numeric string to a number, which won't work.

Whilst you could change the NVL to check for a numeric value you will never encounter, it would be far better to change the condition to:

:OLD.OFFSET != :NEW.OFFSET
or (:OLD.OFFSET is not null and :NEW.OFFSET is null)
or (:OLD.OFFSET is null and :NEW.OFFSET is not null)

That way, you don't have to make up a magic number that your actual values could never be; assuming such a number even exists!

Upvotes: 2

Related Questions