Oracle触发器实现

Oracle trigger implementation

我必须实现一个触发器:

7) Show the DDL for how a trigger can be used to transfer all rental copies from a store being deleted from the Store information table to the central store
8) Show how this trigger can be extended to make sure that the central store is never deleted from the database

到目前为止我已经这样做了:

CREATE OR REPLACE TRIGGER stores
BEFORE DELETE ON stores
FOR EACH ROW
BEGIN
IF DELETING WHERE cvr = 123456789 THEN

Raise_Application_Error (
num => -20050,
msg => 'You can not delete Main Store.');
END IF;
IF DELETING THEN
UPDATE store_id=123456789 ON movies WHERE isActive = 0
END IF;
END;

so main store是用cvr写的,但是编译报错。有什么帮助吗?提前致谢。

您的代码中有两个错误。

  1. 没有 "DELETING WHERE" 表达式,你必须使用两个布尔异常,如下所示:

    如果删除并且:old.cvr = 123456789 那么...

:old.cvr指删除记录中cvr列的值

  1. UPDATE 子句的语法是

    更新table_name SET column_name1 = 值 1, column_name1 = 值 2 其中 where_clause;

在你的情况下可能是这样想的:

UPDATE movies 
    set store_id = 123456789
  WHERE store_id = :old.cvr

我想,我不知道所需的功能