簡體   English   中英

PL/SQL:我的觸發器不適用於引發異常

[英]PL/SQL: My trigger doesn't work with raising exceptions

我的代碼是:

create or replace trigger trig6
before update of min_salary, max_salary on jobs2
for each row
declare
exceptie exception;
cursor c is select salary
from emp_ast
where job_id=:new.job_id;
begin
for i in c loop
if i.salary not between :new.min_salary and :new.max_salary then
raise exceptie;
end if;
end loop;

exception
when exceptie then
dbms_output.put_line('Salariile angajatilor nu se afla intre limitele salariului minim si maxim');
end;
/
update jobs2
set max_salary=1000
where job_id='SA_REP';
/

觸發器編譯成功,但沒有引發任何異常。 我嘗試使用“raise_application_error”並且它有效,但我不知道為什么我不能對異常做同樣的事情。

您放置它的方式(在您發布的觸發器代碼中),它實際上按設計“工作”:如果 emp_ast 表中的salary jobs2 emp_ast中相同job_idmin_salarymax_salary之間,則觸發器顯示消息(使用dbms_output.put_line )在支持它的客戶端上(例如 SQL*Plus 或 SQL Developer 或 TOAD;但不在 Oracle Forms 或 Apex 中)

就這樣。 行已成功更新。

如果你想引發一個錯誤,那么是的——你必須實際引發它,就像你之前對raise_application_error所做的那樣。

同時,Oracle 會按照您的要求執行:檢查某些條件並顯示消息。 這里沒有什么可以阻止update

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM