私はテーブルを持っており、タイムスロットが他のゲストによって既に使用されているかどうかを比較し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