2014-10-05 122 views
0

對於以下觸發器,我收到以下編譯錯誤:缺少SET關鍵字,SQL語句被忽略(在第2行),遇到下列其中一項時遇到符號「文件結束」:(開始case聲明結束異常退出goto if循環mod空pragma提交返回select更新while < <繼續關閉當前刪除讀取鎖定插入打開回滾保存點集合sql執行提交forall合併管道清除(第9行(我已經通過遍歷2打的例子,仍然無法弄清楚我造成什麼樣的合成錯誤,導致這些編譯錯誤..Oracle觸發器編譯錯誤

CREATE OR REPLACE TRIGGER CHANGE_RENTAL_RATE 
BEFORE INSERT ON film FOR EACH ROW 
BEGIN 
UPDATE film 
SELECT * 
SET rental_rate = CASE special_features 
       WHEN 'Trailers' THEN rental_rate := :new.rental_rate + 0.1 
       WHEN 'Commentaries' THEN rental_rate := new.rental_rate + 0.5 
       WHEN 'Deleted Scenes' THEN rental_rate := new.rental_rate + 0.2 
       WHEN 'Behind the Scenes' THEN rental_rate := new.rental_rate - 0.2 
END; 
/
+0

刪除'select *';它不是'update'語句的一部分。 – 2014-10-05 13:22:11

回答

1

您的更新聲明不m因爲它會影響film中的所有行。你正在做一個「之前」的觸發器。也許你想要:

CREATE OR REPLACE TRIGGER CHANGE_RENTAL_RATE 
BEFORE INSERT ON film FOR EACH ROW 
BEGIN 
    if :new.special_features = 'Trailers' THEN :new.rental_rate := :new.rental_rate + 0.1; 
    elsif :new.special_features = 'Commentaries' THEN :new.rental_rate := :new.rental_rate + 0.5; 
    elsif :new.special_features = 'Deleted Scenes' THEN :new.rental_rate := :new.rental_rate + 0.2; 
    elsif :new.special_features = 'Behind the Scenes' THEN :new.rental_rate := :new.rental_rate - 0.2; 
    else :new.special_features := NULL 
    end if; 
END;