次のトリガーを実装する必要があります。
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;