我正在酒店数据库中工作。我试图创建一个触发器,根据当前日期是否在房间的check_in和check_out值之间进行任何新预留之前,更改房间的可用状态。尝试创建触发器时出错(忽略无效的标识符和sql)
我从我的编译器日志2个错误:
SQL Statement Ignored on 'for each row'
和
ora00904: "status_in":invalid identifier
我将不胜感激的任何援助。
表:
create table room(
room_id number(3) constraint room_pk primary key,
room_type varchar2(15) constraint room_fk references roomType,
status char(1)
);
create table reservation(
reservation_id number(6) constraint reservation_pk primary key,
check_in date,
check_out date,
room_id number(3),
guest_id varchar2(5),
foreign key (room_id) references room(room_id),
foreign key (guest_id) references guest(guest_id)
);
触发:
create or replace trigger room_status
before insert on reservation
for each row
declare
status_in room.status%type;
error1 exception;
begin
select status
into status_in
from room
where room_id = :old.room_id;
if sysdate between :old.check_in and :old.check_out then
update room
set status_in = 'F'
where room_id = :old.room_id;
else
update room
set status_in = 'T'
where room_id = :old.room_id;
end if;
exception
when error1 then
raise_application_error(-20100,'Insert Cancelled');
end;
我必须说,我更喜欢具体的Y/N指标这些模糊状态列表。我猜'T'和'F'的意思是'TRUE'和'FALSE',但是'TRUE'是怎么样的状态?在我们处于这个状态时命名列'occupied_yn'(和'varchar2(1)not null',再加上一个只允许'Y'或'N'的检查约束)会使事情变得更加清晰。 –