我遇到了这个触发器的麻烦。我创建了一个程序来检查工资是否在某个边界内。如果它未能落在一定范围内,则提出异常。问题是即使程序编译没有错误,触发器也找不到该程序。
set serveroutput on;
create or replace procedure check_salary (
tmp_id in varchar2,
tmp_sal in number
)
IS
v_sal number(6,0) := tmp_sal;
v_min number(6,0);
v_max number(6,0);
ex_fail exception;
cursor cur_select is
select min_salary, job_id, max_salary
from jobs where job_id = tmp_id;
BEGIN
for rec_something in cur_select loop
v_min := rec_something.min_salary;
v_max := rec_something.max_salary;
if v_sal >= v_min and v_sal <= v_max then
raise ex_fail;
end if;
end loop;
exception
when ex_fail then
dbms_output.put_line('Invalid salary ' || v_sal || ' must be between ' || v_min || ' and ' || v_max ||'.');
END;
/
show errors;
create or replace trigger check_salary_trg
after insert or update on employees
for each row
declare
begin
IF UPDATING or INSERTING THEN
execute check_salary(:NEW.job_id, :NEW.salary);
end if;
end;
/
show errors;
错误讯息:
PROCEDURE check_salary compiled
No Errors.
TRIGGER check_salary_trg compiled
Warning: execution completed with warning
5/13 PLS-00103: Encountered the symbol "CHECK_SALARY" when expecting one of the following:
:= . ( @ % ; immediate
The symbol ":=" was substituted for "CHECK_SALARY" to continue.
答案 0 :(得分:2)
将其更改为:
create or replace trigger check_salary_trg
after insert or update on employees
for each row
begin
IF UPDATING or INSERTING THEN
check_salary(:NEW.job_id, :NEW.salary);
end if;
end;
/
答案 1 :(得分:0)
在PL / SQL块中执行过程时,不要使用
EXECUTE syntax
有关执行的更多信息,请查看以下链接
答案 2 :(得分:0)
堆栈溢出异常是由于在dbms_output.put_line
过程中使用了check_salary
。
SQL * Plus命令set serveroutput on
保留默认大小,您必须指定缓冲区大小或从dbms_output.put_line
过程中删除check_salary
。
为了增加默认缓冲区大小,请使用:
set serveroutput on size 1000000