Question

Write a pl/sql block of code that will make a reservation for a customer for any...

Write a pl/sql block of code that will make a reservation for a customer for any destination. The destination id, number of peolpe going and date will be entered by the user. Your code should calculate the cost and enter the data in the sales table. No destination can have more than 10 people going during the same dates. If the number is greater than 10 raise 'Sold_out' exception and print a message 'Sorry we are sold out for ths destination. Try a different date'. Show the exception worked in your output.

This is the Scrip for this database

drop table zk_sales;
drop table zk_destinations;
drop table zk_hotels;

Create table zk_Hotels
( Hotel_ID      number Primary Key,
Hotel_name    varchar2(25)
);


Create table zk_Destinations
( dest_id        number Primary Key       ,
Dest_name       Varchar2(20)            ,
Dest_location   Varchar2(20)            ,
Price_Person    real                    ,
Hotel_id        number                  ,
Golf            Varchar2(3)             ,
Hiking          Varchar2(3)             ,
Beach           Varchar2(3)             ,
Sking           Varchar2(3)             ,
AmusementPark   Varchar2(3)             ,
CampGround      Varchar2(3)             ,
constraint dest_hotelId_FK foreign Key(hotel_id)
references zk_Hotels(hotel_id)
);

Create table zk_Sales
(Sale_ID        number Primary Key     ,
dest_id number                  ,
Cust_Name       Varchar2(20)            ,
Balance real                    ,
reservation_start_date Date            ,
reservation_end_date    Date            ,
Confirmation    Varchar2(15)            ,
guest_count     number                  ,
constraint      sales_destid_FK Foreign key(dest_id)
references zk_Destinations(dest_id)
);


        

insert into zk_hotels
Values(0,'Camp Ground');
insert into zk_hotels
Values(1,'Hilton Garden');
insert into zk_hotels
Values(2,'Mariott Hotel');
insert into zk_hotels
Values(3,'Double Tree');
insert into zk_hotels values(4, 'on Ship');


insert Into zk_destinations
Values(100, 'Disney World', 'Orlando Fl', 500.0, 1, 'Yes', 'Yes', 'Yes','No', 'Yes', 'Yes');

insert Into zk_destinations
Values(110, 'Europe Cruise', 'San Francisco Ca', 800.0, 4, 'No', 'No', 'No','No', 'No', 'No');

insert Into zk_destinations
Values(120, 'Myrtle Beach', 'Myrtle Beach SC', 700.0, 2, 'Yes', 'Yes', 'Yes','No', 'No', 'No');

insert Into zk_destinations
Values(130, 'Snow Shoe Mtn', 'Silver Spring VA', 400.0, 3, 'No', 'Yes', 'No','Yes', 'No', 'No');

insert Into zk_destinations
Values(140, 'Colorado Ski' , 'Denver Co', 500.0, 3,'No', 'Yes', 'No','Yes', 'No', 'No');

insert Into zk_destinations
Values(150, 'KOA Camp grounds', 'Harrisburg PA', 100.0, 0, 'Yes', 'Yes', 'no','No', 'Yes', 'Yes');

Insert into zk_sales
Values(1, 100, 'Mr. Goodwill', 1000.0, to_date('01/14/2014','mm/dd/yyyy'), to_date( '01/24/2014','mm/dd/yyyy'), 'Confirmed', 2);

Insert into zk_sales
Values(2, 100, 'Mrs. Smith', 1000.0, to_date('01/14/2014','mm/dd/yyyy'), to_date( '01/24/2014','mm/dd/yyyy'), 'Confirmed', 2);

Insert into zk_sales
Values(3, 120, 'Mr. Jones', 2400.0, to_date('02/14/2014','mm/dd/yyyy'), to_date( '02/24/2014','mm/dd/yyyy'), 'Cancelled', 3);

Insert into zk_sales
Values(4, 140, 'Mr. Brown', 600.0, to_date('02/10/2014','mm/dd/yyyy'), to_date( '02/20/2014','mm/dd/yyyy'), 'Confirmed', 1);

Insert into zk_sales
Values(5, 150, 'Ms. Farell', 400.0, to_date('02/20/2014','mm/dd/yyyy'), to_date( '02/27/2014','mm/dd/yyyy'), 'Confirmed', 4);

Insert into zk_sales
Values(6, 150, 'Ms. Long', 200.0, to_date('03/01/2014','mm/dd/yyyy'), to_date( '03/07/2014','mm/dd/yyyy'), 'Confirmed', 2);
Insert into zk_sales
Values(7, 150, 'Mr. Carpenter', 200.0, to_date('04/15/2014','mm/dd/yyyy'), to_date( '04/21/2014','mm/dd/yyyy'), 'Confirmed', 2);
Insert into zk_sales
Values(8, 140, 'Mr. Khan', 1200.00, to_date('01/14/2014','mm/dd/yyyy'), to_date( '1/24/2014','mm/dd/yyyy'), 'Pending', 2);
Insert into zk_sales
Values(9, 100, 'Mr. Krum', 1000.0, to_date('02/20/2014','mm/dd/yyyy'), to_date( '1/27/2014','mm/dd/yyyy'), 'Pending', 2);
Insert into zk_sales
Values(10, 120, 'Mrs Fern', 2000.0, to_date('05/01/2014','mm/dd/yyyy'), to_date( '05/14/2014','mm/dd/yyyy'), 'Confirmed', 5);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

DECLARE
d_id number;
ppl number;
sdt Date;
edt Date;

name varchar2(20);

tot number;
gc number;
cost real;
pr real;
m number;
BEGIN
d_id := :d_id;
ppl := :ppl;
sdt := :sdt;
edt := :edt;
name := :name;
select sum(guest_count) into gc from zk_sales where dest_id = d_id and reservation_start_date=sdt and confirmation ='Confirmed';
tot := gc+ppl;
IF (tot>10) THEN
   dbms_output.put_line('sorry we are sold out for this destination. Try a different date');
ELSE
   select Price_person into pr from zk_destinations where dest_id = d_id;
   cost := ppl * pr;
   select max(sale_id) into m from zk_sales;
   m :=m+1;
   insert into zk_sales values(m, d_id, name, cost, sdt, edt, 'Confirmed', ppl);
END IF;
END;

explanation:

  • declaration section consists of all the variables used in the program
  • d_id -> destination id, sdt -> start date, edt ->end date, ppl-> no. of people, name->name of customer
  • d_id := :d_id   this statement prompts the user to enter d_id value, in the same way all other variables
  • select sum(guest_count).................................................. This query returns no. of people going on a particular date
  • if the total exceeds 10 exception message is printed
  • if not, the values entered by user are inserted into the table zk_sales after calculating the cost
  • for sale_id, I have taken Maximum of previous Id's and added 1 to it, instead of that we can use auto increment of the Id which has to be given while creating the table like create table zk_sales(sale_id number auto_increment, .......................................... primary key(sale_id));

note: please ask, if there are any doubts in the solution, thank you.

Add a comment
Know the answer?
Add Answer to:
Write a pl/sql block of code that will make a reservation for a customer for any...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SQL: CREATE STATEMENT For patients whose last name matches the name entered by the user, display...

    SQL: CREATE STATEMENT For patients whose last name matches the name entered by the user, display their first name, phone number, and doctor's name. Note: Try Davis. (TEXT FOR DATABASE BELOW) DROP TABLE PATIENT; DROP TABLE BILLING; DROP TABLE DOCTOR; CREATE TABLE DOCTOR( DOC_ID VARCHAR2(10) NOT NULL, DOC_NAME VARCHAR2(20), DATEHIRED DATE, SALPERMON NUMBER(8), AREA VARCHAR2(20), SUPERVISOR_ID NUMBER(8), CHGPERAPPT NUMBER(8), ANNUAL_BONUS NUMBER(8), PRIMARY KEY (DOC_ID) ); INSERT INTO DOCTOR VALUES('432', 'Harrison', to_date('05-DEC-1994','dd-mon-yyyy'), 12000, 'Pediatrics', 100, 75, 4500); INSERT INTO DOCTOR VALUES('509',...

  • SQL - create statement for query For each patient, display his or her last name, first...

    SQL - create statement for query For each patient, display his or her last name, first name, and the name of his or her doctor. For each pediatrics patient, display his or her ID and his or her doctor's ID and name. For each doctor, display the name and the name of the doctor's supervisor in alphabetic order of supervisor's name. Include column aliases for clarity. Note: Check for accuracy. For each doctor in one of the two areas entered...

  • Provide the syntax answers for the following script, doesn't matter what table or columns. CREATE TABLE...

    Provide the syntax answers for the following script, doesn't matter what table or columns. CREATE TABLE customer (c_id NUMBER(5), c_last VARCHAR2(30), c_first VARCHAR2(30), c_mi CHAR(1), c_birthdate DATE, c_address VARCHAR2(30), c_city VARCHAR2(30), c_state CHAR(2), c_zip VARCHAR2(10), c_dphone VARCHAR2(10), c_ephone VARCHAR2(10), c_userid VARCHAR2(50), c_password VARCHAR2(15), CONSTRAINT customer_c_id_pk PRIMARY KEY (c_id)); CREATE TABLE order_source (os_id NUMBER(3), os_desc VARCHAR2(30), CONSTRAINT order_source_os_id_pk PRIMARY KEY(os_id)); CREATE TABLE orders (o_id NUMBER(8), o_date DATE, o_methpmt VARCHAR2(10), c_id NUMBER(5), os_id NUMBER(3), CONSTRAINT orders_o_id_pk PRIMARY KEY (o_id), CONSTRAINT orders_c_id_fk FOREIGN...

  • Q2. Retrieve the names of all employees from the employee table to produce output on CSV...

    Q2. Retrieve the names of all employees from the employee table to produce output on CSV format or delimited format with a common delimeter, rather than separete columns. Hint:Put the whole row into a string with a semicolon as the seperator(delimeter) between thecolumns: FORMAT:(fname;minit;lname) Example: EMPLOYEES -------------- James;E;Borg Frank;T;Wong Q3. Write a query to show the employees name from the employee table in this format: first letter of the first name, followed by a dot, a blank, and the full...

  • Oracle 12c SQL Chapter 12 Determine which orders were shipped to the same state as order...

    Oracle 12c SQL Chapter 12 Determine which orders were shipped to the same state as order 1014. CREATE TABLE Orders (Order# NUMBER(4), Customer# NUMBER(4), OrderDate DATE NOT NULL, ShipDate DATE, ShipStreet VARCHAR2(18), ShipCity VARCHAR2(15), ShipState VARCHAR2(2), ShipZip VARCHAR2(5), ShipCost NUMBER(4,2), CONSTRAINT orders_order#_pk PRIMARY KEY(order#), CONSTRAINT orders_customer#_fk FOREIGN KEY (customer#) REFERENCES customers(customer#)); INSERT INTO ORDERS VALUES (1000,1005,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('02-APR-09','DD-MON-YY'),'1201 ORANGE AVE', 'SEATTLE', 'WA', '98114' , 2.00); INSERT INTO ORDERS VALUES (1001,1010,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('01-APR-09','DD-MON-YY'), '114 EAST SAVANNAH', 'ATLANTA', 'GA', '30314', 3.00); INSERT INTO ORDERS VALUES (1002,1011,TO_DATE('31-MAR-09','DD-MON-YY'),TO_DATE('01-APR-09','DD-MON-YY'),'58...

  • I am using oracle sql developer to create some queries to generated reports and it is...

    I am using oracle sql developer to create some queries to generated reports and it is not working. I am not sure how to use count, group by, and order by. Help me fix my query and explain to me how you did, so can do it next time. Also, I have to convert this query to a stored procedure, so can you help me do it too? Here is my query: SELECT COUNT(GUEST.FIRSTNAME), GUEST.FIRSTNAME, GUEST.LASTNAME, GUEST.GUESTTYPE, RESERVATION.RESERVATIONDATE, GUEST.EMAIL, FROM...

  • Oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DRO...

    oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DROP TABLE BOOKS; DROP TABLE PROMOTION; DROP TABLE AUTHOR; DROP TABLE CUSTOMERS; DROP TABLE PUBLISHER; CREATE TABLE Customers ( Customer# NUMBER(4), LastName VARCHAR2(10) NOT NULL, FirstName VARCHAR2(10) NOT NULL, Email VARCHAR(40), Address VARCHAR2(20), City VARCHAR2(12), State VARCHAR2(2), Zip VARCHAR2(5), Referred NUMBER(4), Region CHAR(2), CONSTRAINT customers_customer#_pk PRIMARY KEY(customer#) ); INSERT INTO CUSTOMERS VALUES (1001, 'MORALES', 'BONITA', '[email protected]', 'P.O. BOX 651', 'EASTPOINT', 'FL', '32328', NULL, 'SE'); INSERT INTO CUSTOMERS VALUES...

  • Query #2:       List the name of the project and total number of hours worked on by...

    Query #2:       List the name of the project and total number of hours worked on by all the employees on this project, also report the number of employees working on each project. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null,...

  • Query 1: Retrieve names of all the projects as well as First and Last name of...

    Query 1: Retrieve names of all the projects as well as First and Last name of managers if they are working on any of these projects. Database: //STEP #1: CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null, Mgr_start_date date, primary key (dnumber)); CREATE...

  • I need help for SQL homework. the question: the code for part 1,2: drop table Customer;...

    I need help for SQL homework. the question: the code for part 1,2: drop table Customer; drop table Company; drop table Cruise; drop table TravelAgent; drop table Reservation; drop sequence customerID_seq; drop sequence cruiseID_seq; drop sequence travelAgentID_seq; drop sequence reservationID_seq; create table Customer( customerID number, firstName varchar2(15), lastName varchar2(15), address varchar2(30), phone number(10) not null, age number(3), Constraint Customer_PK Primary Key (customerID), constraint Customer_unique unique (firstName,lastName,phone), constraint Customer_check check(phone is not null) ); create sequence customerID_seq start with 1 increment...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT