0

当我尝试编译此 plsql 时,我不断收到此错误消息:

'F_checksal is not a procedure or is undefined'

这是代码:

declare
  e_high_increase EXCEPTION;
  old_sal NUMBER;
  function f_checkSal(i_sal number,i_old_sal IN OUT NUMBER) return VARCHAR2 is
  begin
  if((i_sal/old_sal)*100>300) then
  raise e_high_increase;
  else  
  return 'yes';
  end if;
  exception when e_high_increase then
  insert into t_logerror(error_tx) values ('this is user exception');
  dbms_output.put_line('this is user exception');
  return 'No';
  end;
begin
select sal into old_sal FROM emp where empno=153;
f_checksal(30000,old_sal);
update emp set sal=30000 where empno=153;  
end;
4

2 回答 2

1

只是您对函数的调用需要更改。

您可以通过调用过程(例如DBMS_OUTPUT.put_line( f_checksal(30000,old_sal));)来使用结果,或者将其分配给局部变量,例如RESULT := f_checksal(30000,old_sal);

于 2013-04-03T03:43:40.527 回答
0

你的语法很差。您需要先创建函数,然后在 pl/sql 块中引用它:

步骤1 :

CREATE OR REPLACE FUNCTION f_checksal (i_sal NUMBER, i_old_sal IN OUT NUMBER)
   RETURN VARCHAR2
IS
   old_sal           NUMBER;
   e_high_increase   EXCEPTION;
BEGIN
   IF ((i_sal / old_sal) * 100 > 300)
   THEN
      RAISE e_high_increase;
   ELSE
      RETURN 'yes';
   END IF;
EXCEPTION
   WHEN e_high_increase
   THEN
      INSERT INTO t_logerror
                  (error_tx
                  )
           VALUES ('this is user exception'
                  );

      DBMS_OUTPUT.put_line ('this is user exception');
      RETURN 'No';
END;
/

第2步:

DECLARE
   old_sal   NUMBER;
   RESULT    VARCHAR2 (100);
BEGIN
   SELECT sal
     INTO old_sal
     FROM emp
    WHERE empno = 153;

   RESULT := f_checksal (30000, old_sal);

   UPDATE emp
      SET sal = 30000
    WHERE empno = 153;
END;

请注意,您的函数有一个您没有在调用代码中分配的返回值。

于 2013-04-01T15:18:26.353 回答