表上触发器访问自己表的问题

create or replace trigger zxb
after update of 是否报到 on zxb_a
for each row
declare num number:=0;
        lou varchar2(100):='';
        room varchar2(100):='';
        num_max number:=0;
begin
if updating then
select max(nvl(bed,0)) into num from zxb_a a  where substr(a.xh,1,6)=substr(:old.xh,1,6) and a.xb=:old.xb and a.xz=:old.xz and bed is not null ;
if num=0 then
select 起始序号 into num  from fenpei where 起始序号 is not null and bjbh=substr(:old.xh,1,6) and 学制=:old.xz and 性别=:old.xb;
end if ;
select 最大序号 into num_max  from fenpei where 最大序号 is not null and bjbh=substr(:old.xh,1,6) and 学制=:old.xz and 性别=:old.xb;
if num>1 and num<=num_max then
num:=num+1 ;
end if;
select room,lou into room,lou from room where 序号=num;
if num>num_max then
select d.楼号,d.宿舍号 into lou,room  from jidong  d where d.学制=:old.xz and  性别=:old.xb and  系别=substr(:old.xh,1,1) and xh is null;
update jidong set xh=:old.xh;
end if ;

update zxb_a a set a.bed=num,a.lou=lou,a.room=room;
end if;
end zxb;

create table ZXB_A
(
  ID       VARCHAR2(20),
  XH       VARCHAR2(255),
  BH       VARCHAR2(255),
  XM       VARCHAR2(255),
  XB       VARCHAR2(255),
  MZM      VARCHAR2(255),
  CSNY     VARCHAR2(50),
  JG       VARCHAR2(255),
  SYM      VARCHAR2(255),
  BMMC     VARCHAR2(255),
  NJ       VARCHAR2(50),
  XBMC     VARCHAR2(255),
  XJQK     VARCHAR2(255),
  BJ       VARCHAR2(255),
  XZ       VARCHAR2(255),
  XBDM     VARCHAR2(255),
  ZYDM     VARCHAR2(255),
  SYLB     VARCHAR2(255),
  SYXZ     VARCHAR2(255),
  ZYMC     VARCHAR2(255),
  SFZH     VARCHAR2(255),
  是否报到 VARCHAR2(50),
  报到时间 VARCHAR2(50),
  操作人   VARCHAR2(50),
  备注     VARCHAR2(50),
  TEL      VARCHAR2(50),
  是否发送 VARCHAR2(50),
  BED      NUMBER,
  LOU      VARCHAR2(100),
  ROOM     VARCHAR2(100)
)
提示:
SQL> update zxb_a a set a.是否报到='是' where xh='080602121';

update zxb_a a set a.是否报到='是' where xh='080602121'

ORA-04091: 表 DEPUSER.ZXB_A 发生了变化,触发器/函数不能读
ORA-06512: 在"DEPUSER.ZXB", line 8
ORA-04088: 触发器 'DEPUSER.ZXB' 执行过程中出错

我想实现表A的“是否报到”列修改为“是” 的时候,触发查找各班级的最大序号,将这个被修改的学生的学生序号+1

谢谢。
我也来说两句 查看全部回复

最新回复

  • stpwy (2008-9-02 16:53:46)

    在触发器中,是不能访问被触发表的
  • jametong (2008-9-02 16:55:52)

    如果是修改当前记录,, 可以直接使用:new.col_name := xxx 来进行修改..

    要查询其他信息,,就没有办法了.. 因为系统无法判断是否会导致trigger的级联..
  • sinboer (2008-9-29 16:29:48)

    知道触发器不能引用自己了。
  • h2004l (2008-10-08 14:00:56)

    after update of 是否报到 on zxb_a

    这句改为 before update of 是否报到 on zxb_a
    否则不能在出发其中更新自身表

    update zxb_a a set a.bed=num,a.lou=lou,a.room=room;
    这句改为:
    :new.bed:= num;
    :new.lou:= lou;
    :new.room:= room;