【发布时间】:2013-02-26 07:04:32
【问题描述】:
我有一张桌子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
【问题讨论】:
-
oracle pl/sql中有when构造吗?如果不是,您可能想要使用上面使用的 IF 语句。
标签: sql oracle syntax triggers