当我尝试编译此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;
答案 0 :(得分:1)
只需要对您的功能进行调用即可。
您可以通过调用过程(例如DBMS_OUTPUT.put_line( f_checksal(30000,old_sal));
)来使用结果,或者将其分配给局部变量,例如RESULT := f_checksal(30000,old_sal);
答案 1 :(得分: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;
请注意,您的函数具有您未在调用代码中指定的返回值。