如果在工作室表中找到该人并且新工资<25000,我需要创建一个触发器以防止更新人员表中的工资。 那些是我的桌子:
CREATE TABLE persons
(id_person NUMBER (15),
name VARCHAR2 (20),
address VARCHAR2 (20),
sex CHAR (1),
birthdate DATE,
salary NUMBER (10));
CREATE TABLE studio
(name VARCHAR2 (20),
address VARCHAR2 (20),
id_president NUMBER (15));
这是触发器,但不起作用:
create or replace trigger president_salary
before update on person
begin
if (new.id_person in ( select id_person from person join studio on (id_person=id.president) where id_person=new.id_person) AND new.salary<25000) then
dbms_outupt.putline('value to small');
end if;
end;
答案 0 :(得分:0)
尝试更像
的触发器create or replace trigger president_salary
before update on person
begin
if (:new.id_person in ( select id_person from person join studio on (id_person=id.president) where id_person=:new.id_person) AND :new.salary<25000) then
dbms_outupt.putline('value to small');
RAISE NO_DATA_FOUND; --or some other exception
end if;
end;
请注意正确使用:new
和RAISE
语句以导致更新失败