I have a stored procedure that updates records if they exist, or adds a new record if they don’t exist.
SQL:
CREATE OR REPLACE PROCEDURE ADDRECORD(ihost VARCHAR, iip VARCHAR)
AS
rc VARCHAR(4000);
ROWCOUNT NUMBER;
BEGIN
rc := 'select count(0) from myTable where physical_host = ihost and primary_ip = iip';
ROWCOUNT := to_number(rc, '99');
IF ROWCOUNT = 1 THEN
UPSERTRECORD(ihost, iip);
ELSE
INSERT INTO myTable(PHYSICAL_HOST, PRIMARY_IP)
VALUES (ihost, iip);
INSERT INTO IP (IP, IP_IND) VALUES (iip, 'V');
END IF;
END ADDRECORD;
The UPSERTRECORD is another stored procedure that is being called. It works fine. In fact, the error is occurring on the line that contains the to_number. The error is :
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
Is there another way to do this? Sorry, I’m not super experienced with SQL, but I need to get this figured out.
Do