SQL-PL触发器编译错误

时间:2012-11-29 05:12:19

标签: sql oracle

我正在尝试创建一个触发器,当我们从nm_employees表中删除值时,该触发器将值输入到表terminate_employees中。我已经编写了触发器,但我收到PL语句的编译错误。有什么想法吗?

CREATE TABLE nm_departments(
dept2 varchar(20),
CONSTRAINT empPK PRIMARY KEY (dept2)
);

CREATE TABLE nm_employees(
name varchar(20),
dept varchar(20),
CONSTRAINT departments FOREIGN KEY (dept) REFERENCES nm_departments (dept2)ON DELETE     CASCADE
);

CREATE TABLE terminated_employees(
te_name varchar(20),
te_dept varchar(20)
);

CREATE OR REPLACE TRIGGER DeleteCustomer
BEFORE DELETE ON nm_employees
FOR EACH ROW
BEGIN
INSERT INTO terminated_employees (te_name,te_dept)
VALUES(:Old.te_name, :Old.te_dept);
END DeleteCustomer;

1 个答案:

答案 0 :(得分:1)

这将编译,如果您在* nm_employees *上写入触发器,那么这将是您必须编写的代码

 CREATE TABLE nm_departments(
    dept2 varchar(20),
    CONSTRAINT empPK PRIMARY KEY (dept2)
    );

CREATE TABLE nm_employees(
name varchar(20),
dept varchar(20),
CONSTRAINT departments FOREIGN KEY (dept) REFERENCES nm_departments (dept2)ON DELETE     CASCADE
);

CREATE TABLE terminated_employees(
te_name varchar(20),
te_dept varchar(20)
);

CREATE OR REPLACE TRIGGER DeleteCustomer
BEFORE DELETE ON nm_employees
FOR EACH ROW
BEGIN
INSERT INTO terminated_employees (te_name,te_dept)
VALUES(:Old.name, :Old.dept);
END DeleteCustomer;