CREATE or REPLACE Trigger Unavailable_Rule
BEFORE INSERT ON Transaction
FOR EACH ROW
BEGIN
IF :new.Date_Rented_Out is not null AND :new.Date_Returned is NULL AND Num_Copies=1
THEN
UPDATE Video
set Num_Copies = Num_Copies - 1,
Status = 'Unavailable'
where Vid_Num = :new.Vid_Num;
ELSE
Num_Copies = Num_Copies - 1;
End IF;
END;
/
show errors;
6/4 PL/SQL: SQL Statement ignored
7/15 PL/SQL: ORA-00971: missing SET keyword
13/13 PLS-00103: Encountered the symbol "=" when expecting one of the f ollowing: := . ( @ % ;
14/2 PLS-00103: Encountered the symbol "END"
答案 0 :(得分:1)
您的update
声明错误。而不是:
UPDATE Video
Num_Copies = Num_Copies -1
set Status = 'Unavailable'
where Vid_Num = :new.Vid_Num;
在Num_Copies
:
set
UPDATE Video
set Num_Copies = Num_Copies - 1,
Status = 'Unavailable'
where Vid_Num = :new.Vid_Num;
编辑:
您的if
声明可以替换为:
UPDATE Video
set Num_Copies = Num_Copies - 1,
Status = (case when :new.Date_Rented_Out is not null AND :new.Date_Returned is NULL AND Num_Copies = 1 then 'Unavailable'
else status
end)
where Vid_Num = :new.Vid_Num;