我试图在一个sql文件中创建多个触发器。代码如下:
CREATE OR REPLACE TRIGGER trigger_selling_price_change
AFTER INSERT OR UPDATE ON SellingPrice
FOR EACH ROW
BEGIN
dbms_output.put_line('price of phone updated');
INSERT INTO LogSellingPriceChange
VALUES(sysdate, phone_id, :old.price, :new.price);
END;
/
CREATE OR REPLACE TRIGGER trigger_purchase_cost_change
AFTER INSERT OR UPDATE ON PurchaseCost
FOR EACH ROW
BEGIN
dbms_output.put_line('purchase cost updated');
INSERT INTO LogPurchaseCostChange
VALUES(sysdate, phone_id, :old.cost, :new.cost);
END;
/
CREATE OR REPLACE TRIGGER trigger_inventory_addition
AFTER INSERT ON Inventory
FOR EACH ROW
BEGIN
dbms_output.put_line('enlisted new phones in database');
INSERT INTO LogInventoryAddition
VALUES(sysdate, phone_id, :old.quantity, :new.quantity);
END;
/
但是当我在pl / sql中执行它时,我得到Warning: Trigger created with compilation errors.
的三倍。
执行show_errors
后,我得到以下输出:
Errors for TRIGGER TRIGGER_INVENTORY_ADDITION:
LINE/COL ERROR
-------- -----------------------------------------------------------------
3/2 PL/SQL: SQL Statement ignored
4/18 PL/SQL: ORA-00984: column not allowed here
查询中包含的表的声明如下:
CREATE TABLE Inventory(
id number,
phone_id number,
quantity number,
PRIMARY KEY (id),
FOREIGN KEY (phone_id) REFERENCES Phone(id)
);
CREATE TABLE PurchaseCost(
id number,
phone_id number,
cost number,
PRIMARY KEY(id),
FOREIGN KEY (phone_id) REFERENCES Phone(id)
);
CREATE TABLE SellingPrice(
id number,
phone_id number,
price number,
PRIMARY KEY(id),
FOREIGN KEY (phone_id) REFERENCES Phone(id)
);
CREATE TABLE LogSellingPriceChange(
change_date date,
phone_id number,
old_price number,
new_price number,
FOREIGN KEY(phone_id) REFERENCES Phone(id)
);
CREATE TABLE LogPurchaseCostChange(
change_date date,
phone_id number,
old_price number,
new_price number,
FOREIGN KEY(phone_id) REFERENCES Phone(id)
);
CREATE TABLE LogInventoryAddition(
addition_date date,
phone_id number,
old_quantity number,
new_quantity number,
FOREIGN KEY(phone_id) REFERENCES Phone(id)
);
成功创建表后,我执行了用于创建触发器的文件。但是,我没有插入任何值。
答案 0 :(得分:1)
“不允许列”错误,因为您正尝试在没有伪密钥phone_id
或:new
的情况下直接访问:old
列,
CREATE OR REPLACE TRIGGER trigger_selling_price_change
AFTER INSERT OR UPDATE ON SellingPrice
FOR EACH ROW
BEGIN
dbms_output.put_line('price of phone updated');
INSERT INTO LogSellingPriceChange
VALUES(sysdate, :new.phone_id, :old.price, :new.price);
END;
/
您还需要更改其他触发器。