我想在将新影片插入FILM表时创建一个触发器。
我所做的是,
CREATE OR REPLACE TRIGGER RENTALRATE_TRIGGER
BEFORE INSERT OR UPDATE ON FILM
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
IF :NEW.SPECIAL_FEATURES LIKE '%Trailers%' THEN
UPDATE FILM SET RENTAL_RATE = :NEW.RENTAL_RATE + .10;
IF :NEW.SPECIAL_FEATURES LIKE '%Commentaries%' THEN
UPDATE FILM SET RENTAL_RATE = :NEW.RENTAL_RATE + .50;
IF :NEW.SPECIAL_FEATURES LIKE '%Deleted Scenes%' THEN
UPDATE FILM SET RENTAL_RATE = :NEW.RENTAL_RATE + .20;
IF :NEW.SPECIAL_FEATURES LIKE '%Behind the Scenes%' THEN
UPDATE FILM SET RENTAL_RATE = :NEW.RENTAL_RATE - .20;
END IF;
END RENTALRATE_TRIGGER;
/
创建触发器后,我收到此错误。
LINE/COL ERROR
-------- -----------------------------------------------------------------
11/5 PLS-00103: Encountered the symbol "RENTALRATE_TRIGGER" when
expecting one of the following:
if
SPECIAL_FEATURES列可以是这样的,“预告片,幕后花絮”
感谢。
答案 0 :(得分:0)
您不应该在触发器中更新同一个表:
CREATE OR REPLACE TRIGGER RENTALRATE_TRIGGER
BEFORE INSERT OR UPDATE
ON FILM
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
IF :NEW.SPECIAL_FEATURES LIKE '%Trailers%'
THEN
:NEW.RENTAL_RATE := :NEW.RENTAL_RATE + .10;
ELSIF :NEW.SPECIAL_FEATURES LIKE '%Commentaries%'
THEN
:NEW.RENTAL_RATE := :NEW.RENTAL_RATE + .50;
ELSIF :NEW.SPECIAL_FEATURES LIKE '%Deleted Scenes%'
THEN
:NEW.RENTAL_RATE := :NEW.RENTAL_RATE + .20;
ELSIF :NEW.SPECIAL_FEATURES LIKE '%Behind the Scenes%'
THEN
:NEW.RENTAL_RATE := :NEW.RENTAL_RATE - .20;
END IF;
END RENTALRATE_TRIGGER;