I've got the following trigger to check if there are available beds in a table called WARD before the user tries to input a value, if not then an error will be shown.
create or replace
trigger checkBeds
before insert or update on INPATIENT_STAY for
each row
Begin
select BEDSAVAIL from WARD where wardnum=:new.WARDNUM;
if(BEDSAVAIL <=0) then
DBMS_OUTPUT.PUT_LINE('There are no beds available.');
end if;
END;
when this is run I get the following error:
Error(2,42): PLS-00049: bad bind variable 'NEW.WARDNUM'
WARD is linked to INPATIENT_STAY by a foreign key in INPATIENT_STAY called WARDNUM
Here's the structure of the WARD table
CREATE TABLE WARD
(
WARDNUM VARCHAR2(20 BYTE) NOT NULL
, NAME VARCHAR2(40 BYTE)
, LOCATION VARCHAR2(20 BYTE)
, TOTALBEDS NUMBER
, TELEXTENTION VARCHAR2(20 BYTE)
, BEDSAVAIL NUMBER
, CONSTRAINT WARD_PK PRIMARY KEY
(
WARDNUM
));
here's the structure of the INPATIENT_STAY table
CREATE TABLE INPATIENT_STAY
(
INPATIENTID VARCHAR2(20 BYTE) NOT NULL
, PATIENTNUMBER VARCHAR2(20 BYTE)
, WADNUM VARCHAR2(20 BYTE)
, DATEONWAITINGLIST DATE
, EXPECTEDDURATION VARCHAR2(20 BYTE)
, EXPECTEDLEAVEDATE DATE
, DATEPLACEDINWARD DATE
, REQWARD VARCHAR2(20 BYTE)
, DATELEFT DATE
, CONSTRAINT INPATIENT_STAY_PK PRIMARY KEY
(
INPATIENTID
)
);
How do I resolve this?