Oracle 语法错误触发器

Posted

技术标签:

【中文标题】Oracle 语法错误触发器【英文标题】:Oracle syntax error trigger 【发布时间】:2014-10-07 01:46:37 【问题描述】:

我已经尝试了 2 个多小时来为这个触发器设置正确的语法,但它一直给我编译错误,有人可以指出我出错的方向吗?

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

film_actor 有以下字段:

actor_id
film_id

film 有以下字段:

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)));

【问题讨论】:

if (select count(column) from table) > 0 then的可能重复 我尝试使用可能重复的帖子中的解决方案,显示/抛出相同的错误 【参考方案1】:

您正在执行 SQL 更新 - 它应该使用常规的 = SQL 运算符,而不是 pl/SQL 的 := 赋值运算符:

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;

【讨论】:

【参考方案2】:

删除 UPDATE 语句的 SET 部分中的冒号。

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;

【讨论】:

以上是关于Oracle 语法错误触发器的主要内容,如果未能解决你的问题,请参考以下文章

将 Oracle 触发器转换为 MySql 触发器

MySQL 触发语法错误

oracle如何检查sql语法错误

Phpmyadmin 在“END”附近创建触发器语法错误

mysql触发器中的语法错误

phpmyadmin mysql 触发语法错误