0

我有一个存储过程,如果记录存在则更新记录,如果记录不存在则添加新记录。

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;

UPSERTRECORD是另一个被调用的存储过程。它工作正常。事实上,错误发生在包含to_number. 错误是:

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

还有另一种方法可以做到这一点吗?抱歉,我对 SQL 不是很有经验,但我需要弄清楚这一点。

4

1 回答 1

2

DECLARE rowcount As Number(38)
select count(*) INTO rowcount from myTable 
where physical_host =  ihost and primary_ip = iip
于 2012-07-26T13:33:33.717 回答