2012-04-25 55 views
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. 
+0

嘗試使用'call',而不是'execute' – GregHNZ 2012-04-25 04:58:13

回答

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; 
/
0

堆棧溢出異常是由於內部check_salary程序使用dbms_output.put_line

SQL * Plus命令set serveroutput on保留小尺寸作爲默認值,您必須指定緩衝區大小或從check_salary過程中刪除dbms_output.put_line

爲了增加默認的緩衝區大小使用此:

set serveroutput on size 1000000