我創建2名錶的員工和客戶。而員工表的代碼是在這裏:在更新觸發在oracle?
create table employees(
employeeNumber number not null,
lastName varchar2(30) not null,
firstName varchar2(30) not null,
email varchar2(50) not null,
officeCode varchar2(10) not null,
assignTo number default null,
jobTitle varchar2(100) not null,
primary key (employeeNumber),
foreign key (officeCode) references offices(officeCode),
foreign key (assignTo) references employees(employeeNumber)
);
這裏assignTo是他自己的表,員工的外鍵和employeeNumber是汽車increment.Some插入樣品是在這裏:
insert into employees (lastName,firstName,email,officeCode,jobTitle)
values ('hasan','rumy','[email protected]','123','manager');
insert into employees (lastName,firstName,email,officeCode,assignTo,jobTitle)
values ('hasan','rakib','[email protected]','123', 1 ,'assistant manager');
客戶表的代碼是在這裏:
create table customers (
customerNumber number not null,
customerName varchar2(50) not null,
phone varchar2(20) not null,
address varchar2(70) not null,
city varchar2(50) not null,
postalCode varchar2(15) not null,
country varchar2(40) not null,
salesRepEmployeeNumber number default null,
primary key(customerNumber),
foreign key (salesRepEmployeeNumber) references employees (employeeNumber)
);
customerNumber之是汽車increment.some樣本投放是在這裏:
insert into customers
(customerName,phone,address,city,postalCode,country,salesRepEmployeeNumber)
values ('roxy','017456','holy park','kolia','Z143','something',1);
現在我創建員工表的更新employeeNumber列之前,其執行對級聯更新觸發器和代碼是在這裏:
create or replace trigger employees_update
before update of employeeNumber on employees
for each row
begin
update employees
set
assignTo = :new.employeeNumber
where assignTo = :old.employeeNumber;
update customers set
salesRepEmployeeNumber = :new.employeeNumber
where salesRepEmployeeNumber = :old.employeeNumber;
end;
/
高於一切是正確的預言,但問題是什麼時候更新員工table.The更新代碼是在這裏:
update employees set employeeNumber = 134 where employeeNumber = 1;
的問題是在這裏:
ORA-04091: table RUMY.EMPLOYEES is mutating, trigger/function may not see it
ORA-06512: at "RUMY.EMPLOYEES_UPDATE", line 2
ORA-04088: error during execution of trigger 'RUMY.EMPLOYEES_UPDATE'
1. update employees set employeeNumber = 134 where employeeNumber = 1;
據我所知,這是一個系統問題,所以我犯了錯誤?我不能讓員工表的外鍵assignTo?還注意到同樣的事情在mysql中正常工作。先行謝謝你回答這個長問題。
運行此'SHOW ERRORS TRIGGER employees_update'獲取更多詳細信息 – Mihai 2014-09-20 17:06:09
查詢'show errors trigger employees_update'發生錯誤,即:「無效的SQL語句」。 – Rumy 2014-09-20 18:05:12