Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write an anonymous PL / SQL program to do ALL of the following: 1 ) check whether there is a ride request with ID

Please write an anonymous PL/SQL program to do ALL of the following:
1) check whether there is a ride request with ID 4.
If there is no such request, print a message 'Invalid ride request' and stop.
2) If the request exists,find all drivers who have a car with car type matching the car type requested in the ride request with ID 4 and have the number of seats greater or equal to the number of passengers in the request. Please print out the name of such drivers and model year of the associated car.
Hint: use select count(*) and if then else for step 1.
Use an explicit cursor for step 2.
[50 points]
drop table trip cascade constraints;
drop table ride_request cascade constraints;
drop table driver_car cascade constraints;
drop table driver cascade constraints;
drop table car cascade constraints;
drop table car_type cascade constraints;
drop table passenger cascade constraints;
create table passenger
(pid int,
pname varchar(50),
pphone varchar(50),
primary key (pid));
insert into passenger values
(1,'Ella','410-458-7897');
insert into passenger values
(2,'Nathan','443-428-7991');
insert into passenger values
(3,'Susan','443-528-7291');
create table driver
(did int,
dname varchar(50),
dphone varchar(50),
primary key(did));
insert into driver
values
(1, 'Adam','301-234-9896');
insert into driver
values
(2, 'Karen','240-134-6750');
insert into driver
values
(3, 'Kevin','410-324-5640');
create table car_type
(ctid int,
ctname varchar(50),
primary key(ctid));
insert into car_type values(1,'Economy');
insert into car_type values(2,'Comfort');
insert into car_type values(3,'Luxury');
create table car
(cid int,
ctid int,
cmodel varchar(50),
cyear int,
color varchar(20),
num_seats int,
primary key(cid),
foreign key (ctid) references car_type);
insert into car values
(1,1, 'Toyota Camry', 2014,'Silver',4);
insert into car values
(2,2, 'Lexus RX',2022,'Black',5);
insert into car values
(3,3, 'Lexus RXL',2022,'Black',7);
insert into car values
(4,2, 'Toyota Highlander', 2020,'Black',7);
insert into car values
(5,2, 'Ford Explorer', 2020,'Black',7);
create table driver_car
(did int,
cid int,
primary key(did,cid),
foreign key(did) references driver,
foreign key(cid) references car);
insert into driver_car
values(1,1);
insert into driver_car
values(2,2);
insert into driver_car
values(3,3);
insert into driver_car
values(3,1);
insert into driver_car
values(2,4);
insert into driver_car
values(3,5);
create table ride_request
(rid int,
pid int,
ctid int,
rtime timestamp,
pickup_loc varchar(100),
dropoff_loc varchar(100),
num_passengers int,
est_fare number,
primary key(rid),
foreign key(pid) references passenger,
foreign key(ctid) references car_type);
insert into ride_request
values(1,1,1,timestamp '2024-3-112:05:00.00','UMBC Lot 9','Baltimore Inner Harbor',1,22);
insert into ride_request
values(2,2,2,timestamp '2024-4-112:05:00.00','UMBC Lot 9','Baltimore Inner Harbor',5,30);
insert into ride_request
values(3,3,3,timestamp '2024-5-112:05:00.00','10000 Blatimore National Pike, Ellicott City','BWI',7,80);
insert into ride_request
values(4,1,2,timestamp '2024-6-112:05:00.00','10000 Blatimore National Pike, Ellicott City','UMBC',7,52);
create table trip
(tid int,
rid int,
did int,
cid int,
start_time timestamp,
end_time timestamp,
fare number,
rating int,
primary key(tid),
foreign key(rid) references ride_request,
foreign key(did) references driver,
foreign key(cid) references car);
insert into trip values
(1,1,1,1,timestamp '2024-3-112:15:00.00',timestamp '2024-3-112:30:00.00',21,5);
insert into trip values
(2,2,2,2,timestamp '2024-4-112:15:00.00',timestamp '2024-4-112:35:00.00',31,4);
insert into trip values
(3,3,3,3,timestamp '2024-5-112:15:00.00',timestamp '2024-5-112:45:00.00',81,5);
commit;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions