2

我正在尝试创建一个在对我的“客户”表进行更新时触发的触发器。我希望触发器将 cust_no、cust_name、contact 和 sysdate 写入另一个名为 Customer_Changelog 的表。

我好像运气不太好。。。

这是我到目前为止所拥有的:

CREATE OR REPLACE TRIGGER Customer_Up_Tr
AFTER UPDATE OF cust_name, contact ON N_Customer
FOR EACH ROW
WHEN (OLD.contact <> 1 AND NEW.contact = 1 OR OLD.cust_name <> 1 AND NEW.cust_name = 1)
DECLARE
lv_cust_no NUMBER;
lv_cust_name VARCHAR(20);
lv_contact VARCHAR(20);
BEGIN
SELECT cust_no INTO lv_cust_no FROM N_Customer WHERE cust_no = :OLD.cust_no;
SELECT cust_name INTO lv_cust_name FROM N_Customer WHERE cust_name = :OLD.cust_name;
SELECT contact INTO lv_contact FROM N_Customer WHERE contact = :OLD.contact;
INSERT INTO
Customer_changelog (lv_cust_no,lv_cust_name, lv_contact) VALUES (cust_no, cust_name, contact);
END;
/

它向我抛出了这些错误:

9/1    PL/SQL: SQL Statement ignored
10/86  PL/SQL: ORA-00984: column not allowed here

如果我能指出正确的方向,我将不胜感激。

4

1 回答 1

4

您可以像这样简单地编写触发器,

create or replace 
TRIGGER Customer_Up_Tr
     AFTER UPDATE OF cust_name, contact ON N_Customer
     FOR EACH ROW
     WHEN (OLD.contact <> 1 AND NEW.contact = 1 OR OLD.cust_name <> 1 AND NEW.cust_name = 1)
BEGIN     
     INSERT INTO customer_changelog (cust_no, cust_name, contact) VALUES (:OLD.cust_no, :OLD.cust_name, :OLD.contact);
END;
于 2013-10-08T03:36:37.817 回答