我必须实现以下触发器:
1960 年以后的选举,每个选举年的总票数不超过 538
但是,我得到了变异表错误。我明白为什么我会收到错误消息,但我看不到其他解决方案(带触发器)。我可以创建一个临时表,但我只想拥有触发器。这是代码:
CREATE OR REPLACE TRIGGER restrict_election_votes
after INSERT OR UPDATE ON election
for each row
declare
v_nbofvotes number;
v_eleyr election.election_year%type :=:NEW.election_year;
v_votes election.votes%type :=:NEW.VOTES;
begin
select sum(votes)
into v_nbofvotes
from election
where election_year=v_eleyr;
if(v_votes+v_nbofvotes >538)
THEN
RAISE_APPLICATION_ERROR(-20500, 'Too many votes');
END IF;
END;
update election
set votes=175
where candidate='MCCAIN J'
and election_year=2008;