下面是一个触发器
create or replace trigger d_update
  after delete or update of deptno on d
  for each row
begin
  if (updating and :old.deptno != :new.deptno) then
    update e set deptno = :new.deptno where deptno = :old.deptno;
  end if;
  if deleting then
    delete e when deptno = :old.deptno;
  end if;
end;在编译的时候产生错误
SQL> show errors
Errors for TRIGGER SCOTT.D_UPDATE:
 
LINE/COL ERROR
-------- -------------------------------------
6/19     PL/SQL: ORA-00933: SQL 命令未正确结束
6/5      PL/SQL: SQL Statement ignored请问一下,上面的错误如何修改,谢谢

解决方案 »

  1.   

    注意红色部分,修改为:
    create or replace trigger d_update
      after delete or update of deptno on d
      for each row
    begin
      if (updating and :old.deptno != :new.deptno) then
        update e set deptno = :new.deptno where deptno = :old.deptno;
      end if;
      if deleting then
        delete from e where deptno = :old.deptno;
      end if;
    end;
      

  2.   

    如果全角半角的情况注意了,那么,你的语句没错误。!=  和  <> 是等效的delete from a  和 delete a 也是等效的。
      

  3.   

    看来需要再次强调一下了,问题是when而不是delete:create or replace trigger d_update
      after delete or update of deptno on d
      for each row
    begin
      if (updating and :old.deptno != :new.deptno) then
        update e set deptno = :new.deptno where deptno = :old.deptno;
      end if;
      if deleting then
        delete e when deptno = :old.deptno;
      end if;
    end;
      

  4.   

    create or replace trigger d_update
      after delete or update of deptno on d
      for each row
    begin
      if (updating and :old.deptno != :new.deptno) then
        update e set deptno = :new.deptno where deptno = :old.deptno;
      end if;
      if deleting then
        delete from e when e.deptno = :old.deptno;
      end if;
    end;
      

  5.   

    create or replace trigger d_update 
      after delete or update of deptno on d 
      for each row 
    begin 
      if (updating and :old.deptno != :new.deptno) then 
        update e set deptno = :new.deptno where deptno = :old.deptno; 
      end if; 
      if deleting then 
        delete from e where e.deptno = :old.deptno; 
      end if; 
    end;
      

  6.   

    很明显是when用错了,应该是where
      

  7.   

    delete e when deptno = :old.deptno;
    ----》delete e where deptno = :old.deptno;