在Oracle中定义而不是触发后无法更新复杂的视图。 ORA-01779:无法修改映射到非键保留表的列

时间:2018-10-26 13:50:06

标签: sql oracle plsql

即使创建了代替触发器之后,更新复杂视图时也收到错误消息。

错误:

  

ORA-01779:无法修改映射到未保留键的表的列

在复杂视图上更新:

update employee_dep
  set dname='Admin',
      deptno=506
where empno=103;

INSTEAD OF TRIGGER(成功创建):

create or replace trigger trigg_namew 
instead of insert on employee_dep
for each row
declare 
  rcount number;
begin
  select count(*) into rcount from employ where empno = :new.empno;
  if (rcount = 0) then
    insert into employ (empno,deptno) values (:new.empno, :new.deptno);
  else
    update employ
      set deptno = :new.deptno
    where empno = :old.empno and deptno = :old.deptno;
  end if;
  select count(*) into rcount from department where deptno = :new.deptno;
  if(rcount = 0) then
    insert into department values (:new.deptno , :new.dname);
  else
    update department
      set dname = :new.dname
    where deptno = :old.deptno and dname = :old.dname;
 end if;
end;

2 个答案:

答案 0 :(得分:2)

您要发布的是对复杂视图的更新,而不是仅在插入时触发的触发器。

更改为INSTEAD OF UPDATE

答案 1 :(得分:1)

也许这是“代替插入”。