2014-10-07 100 views
1

我一直在嘗試2個多小時才能獲得適用於此觸發器的語法,但它一直給我編譯錯誤,請問有人可能會指出我錯誤的方向嗎?Oracle語法錯誤觸發器

[Compilation errors: missing equal sign line 5, sql statement ignored, line 4] 

FILM_ACTOR具有以下字段:

actor_id 
film_id 

膜具有以下字段:

film_id 
rental_rate 


CREATE OR REPLACE TRIGGER TRIGGER_ACTOR_STARRED 
BEFORE INSERT ON film_actor FOR EACH ROW 
BEGIN  
IF :new.actor_id IN (SELECT * 
        FROM V_ACTORS_STARRED) THEN 
    UPDATE film 
    SET rental_rate := rental_rate * 1.10 
    WHERE :new.actor_id = film_actor.actor_id 
    AND film.film_id = film_actor.film_id; 
    END IF; 
END; 
/

我試圖從是選擇如下的觀點:

CREATE OR REPLACE VIEW V_ACTORS_STARRED AS 
SELECT actor_id 
FROM actor 
WHERE actor_id IN 
     (SELECT actor_id 
     FROM film_actor 
     WHERE film_actor.actor_id = actor.actor_id 
     AND film_id IN 
       (SELECT film.film_id 
       FROM film, film_category, category 
       WHERE category.name = 'Documentary' 
       AND film.film_id = film_category.film_id 
       AND film_category.category_id = category.category_id 
       AND rental_rate = (SELECT MAX(rental_rate) 
            FROM film, category, film_category 
            WHERE category.name = 'Documentary' 
            AND film.film_id = film_category.film_id 
            AND film_category.category_id = category.category_id))); 
+0

可能重複)從表)> 0然後](http://stackoverflow.com/questions/10200281/if-select-countcolumn-from-table-0-then) – 2014-10-07 03:04:20

+0

我試過從可能的重複帖子,相同的解決方案工作錯誤正在顯示/拋出 – user3603183 2014-10-07 03:34:01

回答

2

你執行一個SQL更新 - 它應該使用常規= SQL操作,而不是PL/SQL的:=賦值操作符:[IF(SELECT COUNT(列

UPDATE film 
SET rental_rate = rental_rate * 1.10 -- Note ":=" was replaced with "=" 
WHERE :new.actor_id = film_actor.actor_id 
AND film.film_id = film_actor.film_id; 
1

刪除SET部分中的冒號o f UPDATE語句。

UPDATE film 
SET rental_rate = rental_rate * 1.10 
WHERE :new.actor_id = film_actor.actor_id 
AND film.film_id = film_actor.film_id;