Answered step by step
Verified Expert Solution
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 PLSQL program to do ALL of the following:
check whether there is a ride request with ID
If there is no such request, print a message 'Invalid ride request' and stop.
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 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
Use an explicit cursor for step
points
drop table trip cascade constraints;
drop table riderequest cascade constraints;
drop table drivercar cascade constraints;
drop table driver cascade constraints;
drop table car cascade constraints;
drop table cartype cascade constraints;
drop table passenger cascade constraints;
create table passenger
pid int,
pname varchar
pphone varchar
primary key pid;
insert into passenger values
'Ella',;
insert into passenger values
'Nathan',;
insert into passenger values
'Susan',;
create table driver
did int,
dname varchar
dphone varchar
primary keydid;
insert into driver
values
'Adam',;
insert into driver
values
'Karen',;
insert into driver
values
'Kevin',;
create table cartype
ctid int,
ctname varchar
primary keyctid;
insert into cartype values'Economy';
insert into cartype values'Comfort';
insert into cartype values'Luxury';
create table car
cid int,
ctid int,
cmodel varchar
cyear int,
color varchar
numseats int,
primary keycid
foreign key ctid references cartype;
insert into car values
'Toyota Camry', 'Silver',;
insert into car values
'Lexus RX'Black',;
insert into car values
'Lexus RXL'Black',;
insert into car values
'Toyota Highlander', 'Black',;
insert into car values
'Ford Explorer', 'Black',;
create table drivercar
did int,
cid int,
primary keydidcid
foreign keydid references driver,
foreign keycid references car;
insert into drivercar
values;
insert into drivercar
values;
insert into drivercar
values;
insert into drivercar
values;
insert into drivercar
values;
insert into drivercar
values;
create table riderequest
rid int,
pid int,
ctid int,
rtime timestamp,
pickuploc varchar
dropoffloc varchar
numpassengers int,
estfare number,
primary keyrid
foreign keypid references passenger,
foreign keyctid references cartype;
insert into riderequest
valuestimestamp ::'UMBC Lot 'Baltimore Inner Harbor',;
insert into riderequest
valuestimestamp ::'UMBC Lot 'Baltimore Inner Harbor',;
insert into riderequest
valuestimestamp :: Blatimore National Pike, Ellicott City','BWI',;
insert into riderequest
valuestimestamp :: Blatimore National Pike, Ellicott City','UMBC',;
create table trip
tid int,
rid int,
did int,
cid int,
starttime timestamp,
endtime timestamp,
fare number,
rating int,
primary keytid
foreign keyrid references riderequest,
foreign keydid references driver,
foreign keycid references car;
insert into trip values
timestamp ::timestamp ::;
insert into trip values
timestamp ::timestamp ::;
insert into trip values
timestamp ::timestamp ::;
commit;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started