我有一个表BOOKING(hotelID, roomNo, guestID, startDate, endDate)
,我想创建一个触发器来通过比较startDate
和endDate
查看时间段是否已被其他客人占用来进行验证(插入之前)。
CREATE OR REPLACE TRIGGER MYTRIGGER
BEFORE insert ON BOOKING
referencing new as newTuple
for each row
declare
t boolean;
cursor c is
select startDate,endDate from ROOM where hotelID = newTuple.hotelID and ROOMNO = newTuple.roomNo;
BEGIN
t := true;
open c;
loop
fetch c into mStartDate, mEndDate;
exit when c%NOTFOUND;
if (NOT((newTuple.startDate >= mEndDate and newTuple.endDate >= mEndDate)
or(newTuple.startDate <= mStartDate and newTuple.endDate <= mStartDate))) then
t := false;
end if;
end loop;
close c;
WHEN (t=true) then
INSERT INTO BOOKING(hotelID,roomNo,guestID,startDate,endDate)
values(newTuple.hotelID, newTuple.roomNo, newTuple.guestID, newTuple.startDate,
newTyple.endDate);
END;
但它给了我不知道如何解决的语法错误消息(我是 Oracle 新手):
Error(26,3): PLS-00103: Encountered the symbol "WHEN" when expecting one of the following:
( begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << continue close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe purge
The symbol "case" was substituted for "WHEN" to continue.
Error(30,4): PLS-00103: Encountered the symbol ";" when expecting one of the following:
case