【发布时间】:2019-01-04 03:20:34
【问题描述】:
我有两张表,item 和 item_price_history。我想创建一个触发器,在价格表中更改商品价格后插入旧价格记录。这是两张表:
CREATE TABLE item(
item_id DECIMAL(10) NOT NULL,
description VARCHAR(30),
price DECIMAL(10),
PRIMARY KEY (item_id));
CREATE TABLE item_price_history(
item_id DECIMAL(10) NOT NULL,
old_price DECIMAL(10) NOT NULL,
new_price DECIMAL(10) NOT NULL,
date_of_change DATE NOT NULL,
FOREIGN KEY (item_id) references ITEM);
我已经尝试了很多方法来编译它,但这是我作为触发器的:
CREATE OR REPLACE TRIGGER price_hist
AFTER UPDATE ON item
FOR EACH ROW
WHEN (new.price <> old.price)
BEGIN
INSERT INTO item_price_history(item_id, old_price, new_price, date_of_change)
VALUES (:NEW.item_id, :OLD.price, :NEW.price, SYSDATE);
END;
我在更新商品价格后收到以下错误:
Error starting at line : 1 in command -
UPDATE item
SET price = 11
WHERE item_id = 1
Error at Command Line : 1 Column : 8
Error report -
SQL Error: ORA-04098: trigger 'KEVIN.PRICE_UPDATE' is invalid and failed re-validation
04098. 00000 - "trigger '%s.%s' is invalid and failed re-validation"
*Cause: A trigger was attempted to be retrieved for execution and was
found to be invalid. This also means that compilation/authorization
failed for the trigger.
*Action: Options are to resolve the compilation/authorization errors,
disable the trigger, or drop the trigger.
请让我知道您的建议,我已经搜索了高低,但无法找到解决方案。
【问题讨论】:
-
你试过
SHOW ERRORS TRIGGER price_hist;吗?另外,为什么您的错误显示触发器的名称如“KEVIN.PRICE_UPDATE”,而在代码中它是“price_hist”,是不是有两个触发器? -
您的架构中有两个触发器吗?
标签: sql oracle triggers sql-update sql-insert