Practica 15 Workshop 1
Practica 15 Workshop 1
Practica 15 Workshop 1
Table: member
ADDRESS VARCHAR2(100),
CITY VARCHAR2(30),
PHONE VARCHAR2(15),
);
Table: Title
DESCRIPTION VARCHAR2(400),
RELEASE_DATE DATE
);
Table: TITLE_COPY
);
Table: RENTAL
);
);
Create sequences to uniquely iden fy each row in the MEMBER table and the TITLE table. a)
Member number for the MEMBER table: Start with 101; do not allow caching of the values. Name
the sequence MEMBER_ID_SEQ. b) Title number for the TITLE table: Start with 92; do not allow
caching of the values. Name the sequence TITLE_ID_SEQ. c) Verify the existence of the sequences
in the Connec ons Navigator in SQL Developer.
CACHE 0;
START WITH 92
CACHE 0;
Add data to the tables. Create a script for each set of data to be added. a) Add movie tles to the
TITLE table. Write a script to enter the movie informa on. Save the statements in a script named
lab_apcs_4a.sql. Use the sequences to uniquely iden fy each tle. Enter the release dates in the
DD-MONYYYY format. Remember that single quota on marks in a character field must be specially
handled. Verify your addi ons.
VALUES (TITLE_ID_SEQ.NEXTVAL, 'The Shawshank Redemp on', 'Stephen King', 1994, 'Castle Rock
Entertainment');
VALUES (TITLE_ID_SEQ.NEXTVAL, 'The Dark Knight', 'Christopher Nolan', 2008, 'Warner Bros.');
COMMIT;
Add data to the MEMBER table. Save the insert statements in a script named lab_apcs_4b.sql.
Execute commands in the script. Be sure to use the sequence to add the member numbers.
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
VALUES (MEMBER_ID_SEQ.NEXTVAL, 'Velasquez', 'Carmen', '283 King Street', 'Sea le', '206-899-
6666', '08-MAR-1990');
VALUES (MEMBER_ID_SEQ.NEXTVAL, 'Nagayama', 'Midori', '68 Via Centrale', 'Sao Paolo', '254-852-
5764', '17-JUN-1991');
VALUES (MEMBER_ID_SEQ.NEXTVAL, 'Ropeburn', 'Audry', '86 Chu Street', 'Hong Kong', '41-559-87',
'18-JAN-1991');
COMMIT;
SELECT * FROM MEMBER;
Add the following movie copies in the TITLE_COPY table: Note: Have the TITLE_ID numbers
available for this exercise. Title Copy_Id Status Title Copy_Id Willie and Christmas Too 1 AVAILABLE
Willie and Christmas Too 1 Alien Again 1 AVAILABLE Alien Again 1 2 RENTED 2 The Glob 1
AVAILABLE The Glob 1 My Day Off 1 AVAILABLE My Day Off 1 2 AVAILABLE 2 3 RENTED 3 Miracles
on Ice 1 AVAILABLE Miracles on Ice 1 Soda Gang 1 AVAILABLE Soda Gang 1
Add the following rentals to the RENTAL table: Note: The tle number may be different depending
on the sequence number. Title_ Id Copy_ Id Member_Id Book_date Exp_Ret_Date 92 1 101 3 days
ago 1 day ago 93 2 101 1 day ago 1 day from now 95 3 102 2 days ago Today 97 1 106 4 days ago 2
days ago
Create a view named TITLE_AVAIL to show the movie tles, the availability of each copy, and its
expected return date if rented. Query all rows from the view. Order the results by tle.
FROM TITLE t
ON t.TITLE_ID = tc.TITLE_ID
Make changes to the data in the tables. a) Add a new tle. The movie is “Interstellar Wars,” which
is rated PG and classified as a science fic on movie. The release date is 07-JUL-77. The descrip on
is “Futuris c interstellar ac on movie. Can the rebels save the humans from the evil empire?” Be
sure to add a tle copy record for two copies. b) Enter two reserva ons. One reserva on is for
Carmen Velasquez, who wants to rent “Interstellar Wars.” The other is for Mark Quick-to-See, who
wants to rent “Soda Gang.”
VALUES((SELECT TITLE_ID FROM TITLE WHERE TITLE_NAME = 'Soda Gang'), (SELECT TITLE_COPY_ID
FROM TITLE_COPY WHERE TITLE_ID = (SELECT TITLE_ID FROM TITLE WHERE TITLE_NAME = 'Soda
Gang') AND STATUS = 'AVAILABLE' AND ROWNUM = 1), (SELECT MEMBER_ID FROM MEMBER
WHERE FIRST_NAME = 'Mark' AND LAST_NAME = 'Quick-to-See'), SYSDATE, SYSDATE+3);
Customer Carmen Velasquez rents the movie "Interstellar Wars," copy 1. Remove her reserva on
for the movie. Record the informa on about the rental. Allow the default value for the expected
return date to be used. Verify that the rental was recorded by using the view you created
a. Add a PRICE column to the TITLE table to record the purchase price of the video. The
column should have a total length of eight digits and two decimal places. Verify your
modifica ons.
DESCRIBE TITLE;
Customer Carmen Velasquez rents the movie "Interstellar Wars," copy 1. Remove her reserva on
for the movie. Record the informa on about the rental. Allow the default value for the expected
return date to be used. Verify that the rental was recorded by using the view you created.
a. Add a PRICE column to the TITLE table to record the purchase price of the video. The
column should have a total length of eight digits and two decimal places. Verify your
modifica ons.
b. Create a script named p15q7b.sql to update each video with a price according to the following
list.
Create a report tled Customer History Report. This report will contain each customer's history of
ren ng videos. Be sure to include the customer name, movie rented, dates of the rental, and
dura on of rentals. Total the number of rentals for all customers for the repor ng period. Save the
script in a file named p15q8.sql.
FROM MEMBER m
FROM MEMBER m