0

我有以下触发器:

create or replace 
trigger updateBeds
  After insert or update on INPATIENT_STAY for
    each row
Begin
if(:new.INPATIENT_STAY.DATEPLACEDINWARD<=sysdate and :new.INPATIENT_STAY.expectedleavedate>=sysdate)
then 
  update WARD
    set BEDSAVAIL = TOTALBEDS - 1
    where WARDNUM = :new.INPATIENT_STAY.WARDNUM;
end if;
if(:new.INPATIENT_STAY.DATELEFT <= sysdate) then
  update WARD
    set BEDSAVAIL = TOTALBEDS +1
    where WARDNUM = :new.INPATIENT_STAY.WARDNUM;
end if;
END;

totalbeds如果INPATIENT_STAY.DATEPLACEDINWARDINPATIENT_STAY.expectedleavedate小于系统日期,则此触发器旨在从列中减去 1 。此外,如果INPATIENT_STAY.DATELEFT小于或等于系统日期,totalbeds则应增加 1。 通过调用的外键WARD链接到INPATIENT_STAYINPATIENT_STAYWARDNUM

当我尝试编译触发器时,出现以下错误:

Error(2,4): PLS-00049: bad bind variable 'NEW.INPATIENT_STAY'
Error(2,54): PLS-00049: bad bind variable 'NEW.INPATIENT_STAY'
Error(6,21): PLS-00049: bad bind variable 'NEW.INPATIENT_STAY'
Error(8,4): PLS-00049: bad bind variable 'NEW.INPATIENT_STAY'
Error(11,21): PLS-00049: bad bind variable 'NEW.INPATIENT_STAY'

我不确定我在这里做错了什么。任何帮助深表感谢

这些表是:

 WARD
    WARDNUM VARCHAR2(20 BYTE)
    NAME VARCHAR2(40 BYTE)
    TOTALBEDS NUMBER
    BEDSAVAIL NUMBER

INPATIENT_STAY
   INPATIENTID VARCHAR2(20 BYTE)
   WARDNUM VARCHAR2(20 BYTE)
   EXPECTEDLEAVEDATE DATE
   DATEPLACEDINWARD DATE
   DATELEFT DATE
4

1 回答 1

1

要从插入/更新的行访问列的值,只需使用:new.column_name- 您不应该在:new列名和列名之间添加表名,试试这个:

create or replace 
trigger updateBeds
  After insert or update on INPATIENT_STAY for
    each row
Begin
if(:new.DATEPLACEDINWARD<=sysdate and :new.expectedleavedate>=sysdate)
then 
  update WARD
    set BEDSAVAIL = TOTALBEDS - 1
    where WARDNUM = :new.WARDNUM;
end if;
if(:new.DATELEFT <= sysdate) then
  update WARD
    set BEDSAVAIL = TOTALBEDS +1
    where WARDNUM = :new.WARDNUM;
end if;
END;
于 2013-10-31T14:47:48.557 回答