1

我在使用此触发器时遇到了一些问题。我创建了一个程序来检查薪水是否在某个范围内。如果它没有落在某个范围内,则引发异常。问题是即使程序编译没有错误,触发器也找不到程序。

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.
4

3 回答 3

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;
/
于 2012-04-25T06:10:53.620 回答
0

在 PL/SQL 块中执行过程时,不要使用

 EXECUTE syntax

有关执行的更多信息,您可以查看以下链接

http://docstore.mik.ua/orelly/oracle/prog2/ch23_01.htm

于 2012-04-25T11:08:52.813 回答
0

堆栈溢出异常是由于使用了dbms_output.put_line内部check_salary过程。

SQL*Plus 命令set serveroutput on默认保留很小的大小,您必须指定缓冲区大小或dbms_output.put_linecheck_salary过程中删除。

为了增加默认缓冲区大小,请使用:

set serveroutput on size 1000000

于 2013-01-16T12:33:06.650 回答