我有以下触发器:
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.DATEPLACEDINWARD
小于系统日期,则此触发器旨在从列INPATIENT_STAY.expectedleavedate
中减去1。
此外,如果INPATIENT_STAY.DATELEFT
小于或等于系统日期,则totalbeds
应增加1。
WARD
被INPATIENT_STAY
中的INPATIENT_STAY
WARDNUM
相关联
当我尝试编译触发器时,我收到以下错误:
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
答案 0 :(得分: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;