My database is that of a hotel reservation system. My trigger will change the availability status of a room before any new reservations are made based on whether the current date falls between the check_in and check_out values of a room.
I getting the error no data found when attempting to fire the trigger with an insert statement. I would appreciate any assistance with the problem.
Error:
SQL Error: ORA-01403: no data found ORA-06512: at "USER.ROOM_STATUS", line 5 ORA-04088 error during execution of trigger 'USER.ROOM_STATUS' - no data found *Cause: No data was found from the objects
Trigger:
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.room_id = :old.room_id;
if sysdate between :old.check_in and :old.check_out then
update room
set status = 'F'
where room_id = :old.room_id;
else
update room
set status = 'T'
where room_id = :old.room_id;
end if;
exception
when error1 then
raise_application_error(-20100,'Insert Cancelled');
end;
Insert Statement:
insert into reservation
values(reservation_sequence.nextval,to_date('05-03-2017','mm/dd/yyyy'),
to_date('05-07-2017','mm/dd/yyyy'), 116, 170);
Tables:
create table roomType
(room_type varchar2(20) constraint roomType_pk primary key,
room_rate number(4));
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 guest
(guest_id varchar2(5) constraint guest_pk primary key,
first_name varchar2(20),
last_name varchar2(20),
email varchar2(30),
phone varchar2(10));
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));