PROG3040 Assignment 1 – Fall 2013 Glenn Paulley – 2A605, x2525
Assignment Type: INDIVIDUAL
Due Date: 2-October-2013 (Wednesday), 10 a.m.
Submission: via D2L drop-box; please take all of the files documented below and combine them into a single .zip file using WinZip so that your D2L submission is a single .zip file. In addition, paper output (script and results for marking) is due in class on 3 October 2013 (or before).
Instructions:
· Ensure that you have run the latest version of the database creation script files located in K:\GPAULLEY\PROG3040\DATABASES\PLSQL_WORKBOOK\storedb\create_workbook_store.sql to create the required tables and data.
· Familiarize yourself with the assignment standards. You should, at a minimum, capitalize SQL language keywords. Identifiers may be in lower case or mixed case – strive for consistency. Be neat.
Task 1. Database design and functional dependencies. [10 marks]
Closure: Certain functional dependencies imply others. Given a set F of functional dependencies that hold for a table R, the closureF+ of that set is the set of all FDs implied by the FDs in F. F+ can be computed by applying Armstrong’s axioms to F. Furthermore, given a subset Z of the attributes of a table R, and a set F of functional dependencies that hold for R, the closureZ+ of Z is defined as the set X of the attributes of R such that the functional dependency Z X is a member of F+.
If the closures F+ and G+ of two sets of dependencies F and G are equal, then we say that F and G are equivalent.
To repeat from class, here are Armstrong’s axioms for functional dependencies, and additional axioms that can be derived from Armstrong’s original three axioms. Remember that X, Y, and Z are sets of attributes:
1. Inclusion: if Y is a subset of X, then X Y.
2. Augmentation: if X Y then WX WY.
3. Transitivity: if X Y and Y Z then X Z.
Other axioms:
· Self-determination: for any X, X X. X X is known as a trivial functional dependency.
· Union: if X Y and X Z then X YZ.
· Decomposition: if X YZ then X Y and X Z.
· Composition: if X Y and W Z, then XW YZ.
· Pseudo-transitivity: if X Y and WY Z then XW Z.
Example. Suppose we have a table R with non-null attributes A, B, C, D; we commonly write this as
R( A, B, C, D).
Further suppose we have the following set F of non-trivial functional dependencies:
· A B
· B C
· BC D
We can determine the closure A+ of A as follows:
We are given A B. Trivially, attribute A functionally determines itself, so we have A A. Since we are given B C, by transitivity we have A C (because A B and B C, thus A C). Combining these through union, we have A ABC. Finally, with BC D, again by transitivity we have A D, because A BC and BC D, and therefore A D. Combining again, we have A ABCD, that is, A functionally determines all of the attributes of R. (Aside: hence A is called a superkey of R).
Task 1, Question 1:
Suppose we have the table S with non-null attributes A through G; that ...
1. PROG3040 Assignment 1 – Fall 2013 Glenn
Paulley – 2A605, x2525
Assignment Type: INDIVIDUAL
Due Date: 2-October-2013 (Wednesday), 10 a.m.
Submission: via D2L drop-box; please take all of the files
documented below and combine them into a single .zip file
using WinZip so that your D2L submission is a single .zip file.
In addition, paper output (script and results for marking) is due
in class on 3 October 2013 (or before).
Instructions:
· Ensure that you have run the latest version of the database
creation script files located in
K:GPAULLEYPROG3040DATABASESPLSQL_WORKBOO
Kstoredbcreate_workbook_store.sql to create the required
tables and data.
· Familiarize yourself with the assignment standards. You
should, at a minimum, capitalize SQL language keywords.
Identifiers may be in lower case or mixed case – strive for
consistency. Be neat.
Task 1. Database design and functional dependencies. [10
marks]
Closure: Certain functional dependencies imply others. Given a
set F of functional dependencies that hold for a table R, the
closureF+ of that set is the set of all FDs implied by the FDs in
F. F+ can be computed by applying Armstrong’s axioms to F.
Furthermore, given a subset Z of the attributes of a table R, and
a set F of functional dependencies that hold for R, the
closureZ+ of Z is defined as the set X of the attributes of R such
that the functional dependency Z X is a member of F+.
If the closures F+ and G+ of two sets of dependencies F and G
are equal, then we say that F and G are equivalent.
2. To repeat from class, here are Armstrong’s axioms for
functional dependencies, and additional axioms that can be
derived from Armstrong’s original three axioms. Remember that
X, Y, and Z are sets of attributes:
1. Inclusion: if Y is a subset of X, then X Y.
2. Augmentation: if X Y then WX WY.
3. Transitivity: if X Y and Y Z then X Z.
Other axioms:
· Self-determination: for any X, X X. X X is known as a trivial
functional dependency.
· Union: if X Y and X Z then X YZ.
· Decomposition: if X YZ then X Y and X Z.
· Composition: if X Y and W Z, then XW YZ.
· Pseudo-transitivity: if X Y and WY Z then XW Z.
Example. Suppose we have a table R with non-null attributes A,
B, C, D; we commonly write this as
R( A, B, C, D).
Further suppose we have the following set F of non-trivial
functional dependencies:
· A B
· B C
· BC D
We can determine the closure A+ of A as follows:
We are given A B. Trivially, attribute A functionally
determines itself, so we have A A. Since we are given B C, by
transitivity we have A C (because A B and B C, thus A C).
Combining these through union, we have A ABC. Finally, with
BC D, again by transitivity we have A D, because A BC and
BC D, and therefore A D. Combining again, we have A
ABCD, that is, A functionally determines all of the attributes of
R. (Aside: hence A is called a superkey of R).
Task 1, Question 1:
Suppose we have the table S with non-null attributes A through
G; that is, we have
3. S( A, B, C, D, E, F, G).
Suppose we are given that S satisfies the following set G of
non-trivial functional dependencies:
· A B
· BC DE
· AEF G
(1a). Determine the closure { A,C }+ under this set G of
functional dependencies; remember that closure includes self-
determination. Remember from mathematics that a pair of
braces ({}) denotes a set; hence {A,C} denotes a set made up of
the union of attributes from the sets A and C.
Is the closure {A,C }+ equal to (choose one only):
i.) ABC
ii.) ABCDE
iii.) AC
iv.) ABCDEFG
v.) ACDFG
(1b). Is the functional dependency ACF DG implied by G?
(Answer yes or no).
Submit your responses to 1(a) and 1(b) in a separate text file.
Name your file Task1Q1XX.txt where XX are your first and last
initials. You’ll include this file in your D2L submission.
Task 1, Question 2: [30 marks]
Create an SQL script that creates a set of tables in Boyce-Codd
Normal Form to represent entities in an order/entry system.
Note: as is often the case, there is no “right answer” for doing
this; logical database design is always subject to tradeoffs
because normalizing every functional dependency usually isn’t
desirable. For example, we usually do not decompose the
functional dependency address postal code because there is
little value in doing so. An example from the schema used in the
textbook are the superfluous tables for telephone numbers and
street addresses.
This order/entry system will retain information similar to that
modelled by the Video Store schema documented in the
textbook, but with some differences. To prevent confusion with
4. the Video Store tables, prefix all of your table names for this
new set of tables with “PG$_”. Use lowercase and underscores
for table and column names and for constraint names.
Your new schema is to include at least the following
information:
· For each customer:
· Customer number (unique)
· Personal information (names)
· “Ship-to” addresses (multiple addresses per customer)
· Balance
· Credit Limit
· Discount percentage
· For each order:
· Order information: customer number, ship-to address, date of
order
· Detail lines (several per order): item number, quantity ordered
· For each item:
· Item number (unique)
· Manufacturing plants (a plant may manufacture many items;
each item may be manufactured by different plants)
· Quantity-on-hand at each plant
· Stock danger level at each plant
· Item description
· For each plant:
· Mailing Address
· Contact information
· Telephone number
· Assume that the company intends to handle tens of thousands
of items in total, and thousands of orders per month.
· Also, for processing reasons a “quantity outstanding” value is
associated with each detail line of each order; this value is
initially set equal to the quantity of the item ordered and is
progressively reduced to zero as (partial) shipments are made.
If you need to create surrogate keys for entities in this schema,
choose data types and formats that are appropriate for the
purpose. Include comment lines in your schema creation script
5. that documents your proposed surrogate key formats, and why
you chose those formats and data types. In addition to creating
the appropriate tables and their columns, define the appropriate
referential integrity constraints (primary keys and foreign keys)
that relate the tables together. Give each referential constraint
an appropriate name.
Your marks for this question will be based on the “reasonable-
ness” of your design choices. You should provide commentary
(in the form of comments in your SQL script) that explains your
design choices, particularly if there might be debate about such
a choice. Appropriate commentary will enhance your mark.
Create a script file (Task1Q2XX.sql, where XX are your initials
in upper case letters) that creates the tables. You will include
both your completed script file and its output file
(Task1Q2XX.out) to your .zip file submission to D2L.
Task 2. SQL Queries [10 marks each]
Create a script file (Task2XX.sql, where XX are your initials in
upper case letters) to combine the SQL queries for each problem
below, in order. You will submit both your completed script file
and its combined output file (Task2XX.out) to D2L.
1) Write a single SQL query that computes, for each contact, the
average and sum of the rental transactions for rentals that were
made in June 2011 (they could have possibly been returned in
July or later). Include the overall grand total and overall
transaction average in the result. You may not use a UNION
query expression for your answer. For each contact, output:
a. Contact ID
b. Contact last name
c. Contact first name
d. Sum of the contact’s transactions for June 2011, in the format
$9999.99
e. Average of the contact’s transactions for June 2011, in the
format $99.99
f. For the grand total, substitute the literal string ‘June 2011
totals’ for the contact’s last name.
6. g. Output the list of contacts ordered by first name within last
name.
Hints:
i. Use COALESCE() to substitute the ‘June 2011 totals’ string
in the output
ii. Use GROUP BY ROLLUP
iii. Use a derived table in the FROM clause
iv. You will find the EXTRACT() and TO_CHAR() functions
useful
2) Using the Video Store schema, write a query to produce a list
of items that have never been rented. (Note: there is currently
only one, with the Item ID of 1000). Rewrite your query in at
least three different ways – that are semantically equivalent –
that will return the identical result. Your rewrites may not be
trivial ones – for example, reordering tables in the FROM
clause or reordering predicates in the WHERE clause, or
reversing or negating comparison operations.
3) Using the Video Store schema, write a query to produce a
report that lists the number of times each of the Star Wars
movies were rented in October, 2011. Include the total rental
amount for each of the films. Consider only those movies in
Wide Screen format on DVD. Output the ID of each film, its
title, the number of times it was rented in October 2011 (use the
column heading “Rentals”) and the total rental amount for each
film, using proper money formatting in dollars and cents – use
the column header “Total Amt” for this column. Order your
result by film title.
4) Using the HR schema, write a query that lists all of the
departments located in Seattle, Washington, along with their
managers and the start date for each manager. If a department
does not have a manager, output the value “Unknown”. Output
the manager’s start date using the format “YYYY-MM-DD”. If
the start date for that manager is unknown, also use the literal
7. “Unknown”. Use appropriate headings for each column in the
result. Order the list by department name.
Task 3. Supplementary task. [5 marks]
You have come into possession of a vintage VHS tape (on two
cassettes) of the film “Lawrence of Arabia”. Add the tape to the
Item table in the Video Store database using an INSERT
statement that contains the necessary SELECT subquery to
determine the proper item type code for this VHS double-set.
COMMIT the change.
Once the film has been added to the database, re-run your
queries from Task 2, Item 2. Ensure that your queries find both
the new “Lawrence of Arabia” film, and the “Pirates of the
Caribbean” film, both of which have yet to be rented.
After your query executes, delete the “Lawrence of Arabia” film
using a DELETE statement, and COMMIT the deletion as part
of your SQL script.
Create a script file (Task3ExtraXX.sql) that creates the new
item, answers the queries, and deletes the item. Submit to D2L
both your completed script file and output file
(Task3ExtraXX.lst).
create_workbook_store.sql
-- create_store.sql
-- Introcution, Oracle Database 11g PL/SQL Programming
Workbook
-- by Michael McLaughlin and John Harper
--
-- This demonstrates building a DVD, Game Cartridge and VHS
tape store.
8. -- It also highlights constraints and compound check constraints
and
-- seeds the tables with data.
SPOOL create_store.log
SET ECHO OFF
SET FEEDBACK ON
SET NULL '<Null>'
SET PAGESIZE 999
SET SERVEROUTPUT ON
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'SYSTEM_USER') LOOP
EXECUTE IMMEDIATE 'DROP TABLE system_user
9. CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'SYSTEM_USER_S1')
LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE
system_user_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create SYSTEM_USER table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE system_user
( system_user_id NUMBER CONSTRAINT
pk_system_user PRIMARY KEY
, system_user_name VARCHAR2(20) CONSTRAINT
10. nn_system_user_1 NOT NULL
, system_user_group_id NUMBER CONSTRAINT
nn_system_user_2 NOT NULL
, system_user_type NUMBER CONSTRAINT
nn_system_user_3 NOT NULL
, last_name VARCHAR2(20)
, first_name VARCHAR2(20)
, middle_initial VARCHAR2(1)
, created_by NUMBER CONSTRAINT
nn_system_user_4 NOT NULL
, creation_date DATE CONSTRAINT
nn_system_user_5 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_system_user_6 NOT NULL
, last_update_date DATE CONSTRAINT
nn_system_user_7 NOT NULL);
CREATE SEQUENCE system_user_s1 START WITH 1000;
INSERT INTO system_user
VALUES (
1,'SYSADMIN',1,1,1,NULL,NULL,1,SYSDATE,1,SYSDATE);
11. ALTER TABLE system_user ADD CONSTRAINT
fk_system_user_1 FOREIGN KEY(created_by)
REFERENCES system_user(system_user_id);
ALTER TABLE system_user ADD CONSTRAINT
fk_system_user_2 FOREIGN KEY(last_updated_by)
REFERENCES system_user(system_user_id);
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'COMMON_LOOKUP') LOOP
EXECUTE IMMEDIATE 'DROP TABLE common_lookup
CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
12. WHERE sequence_name = 'COMMON_LOOKUP_S1')
LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE
common_lookup_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create COMMON_LOOKUP table and sequence and seed
data.
-- ------------------------------------------------------------------
CREATE TABLE common_lookup
( common_lookup_id NUMBER CONSTRAINT
pk_common_lookup PRIMARY KEY
, common_lookup_table VARCHAR2(30) CONSTRAINT
nn_common_lookup_1 NOT NULL
, common_lookup_column VARCHAR2(30)
CONSTRAINT nn_common_lookup_2 NOT NULL
, common_lookup_type VARCHAR2(30) CONSTRAINT
nn_common_lookup_3 NOT NULL
13. , common_lookup_code VARCHAR2(8)
, common_lookup_meaning VARCHAR2(255)
CONSTRAINT nn_common_lookup_4 NOT NULL
, created_by NUMBER CONSTRAINT
nn_common_lookup_5 NOT NULL
, creation_date DATE CONSTRAINT
nn_common_lookup_6 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_common_lookup_7 NOT NULL
, last_update_date DATE CONSTRAINT
nn_common_lookup_8 NOT NULL
, CONSTRAINT fk_common_lookup_1 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_common_lookup_2 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE INDEX common_lookup_n1
ON common_lookup(common_lookup_table);
14. CREATE UNIQUE INDEX common_lookup_u2
ON
common_lookup(common_lookup_table,common_lookup_colum
n,common_lookup_type);
CREATE SEQUENCE common_lookup_s1 START WITH 1000;
-- ------------------------------------------------------------------
-- Insert Common Lookups.
-- ------------------------------------------------------------------
SELECT 'INSERT COMMON_LOOKUP' AS "Section Header"
FROM dual;
INSERT INTO common_lookup VALUES
(
1,'SYSTEM_USER','SYSTEM_USER_TYPE','SYSTEM_ADMI
N',NULL,'System Administrator'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
(
19. INSERT INTO common_lookup VALUES
(
common_lookup_s1.nextval,'ITEM','ITEM_TYPE','PLAYSTATI
ON2',NULL,'PlayStation2'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
(
common_lookup_s1.nextval,'ITEM','ITEM_TYPE','XBOX',NUL
L,'XBOX'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
(
common_lookup_s1.nextval,'ITEM','ITEM_TYPE','VHS_SINGL
E_TAPE',NULL,'VHS: Single Tape'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
(
20. common_lookup_s1.nextval,'ITEM','ITEM_TYPE','VHS_DOUB
LE_TAPE',NULL,'VHS: Double Tape'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
(
common_lookup_s1.nextval,'ITEM','ITEM_RATING_AGENCY'
,'MPAA','MPAA','Motion Picture Association of America'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
(
common_lookup_s1.nextval,'ITEM','ITEM_RATING_AGENCY'
,'ESRB','ESRB','Entertainment Software Rating Board'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','MPAA
G','G','G - General Audiences: All ages admitted.'
, 1, SYSDATE, 1, SYSDATE);
21. INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','MPAA
PG','PG','PG - Parental guidance suggested: Some material may
not be suitable for children.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','MPAA
PG-13','PG-13','PG-13 - Parents strongly cautioned: Some
material may be inappropriate for children under 13.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','MPAA
R','R','R - Restricted: Under 17 requires accompanying parent or
adult guardian.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','MPAA
NC-17','NC-17','NC-17 - No one 17 and under admitted.'
, 1, SYSDATE, 1, SYSDATE);
22. INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','MPAA
NR','NR','NR - Not Rated.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','ESRB
EC','ED','EC - Early Childhood: Contains content that may be
suitable for ages 3 and older. Contains no material that parents
would find inappropriate.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','ESRB
E','E','E - Everyone: Contains content that may be suitable for
ages 6 and older. Titles in this category may contain minimal
cartoon, fantasy or mild violence and/or infrequent use of mild
language.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
23. ( common_lookup_s1.nextval,'ITEM','ITEM_RATING','ESRB
E10+','E10+','E10+ - Everyone 10+: Contains content that may
be suitable for ages 10 and older. Titles in this category may
contain more cartoon, fantasy or mild violence, mild language,
minimal and/or infrequent blood and/or minimal suggestive
themes.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','ESRB
T','T','T - Teen: Contains content that may be suitable for ages
13 and older. Titles in this category may contain violence,
suggestive themes, crude humor, minimal blood, simulated
gambling, and/or infrequent use of strong language.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','ESRB
M','M','M - Mature: Contains content that may be suitable for
ages 17 and older. Titles in this category may contain intense
violence, blood and gore, sexual content and/or strong
language.'
, 1, SYSDATE, 1, SYSDATE);
24. INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','ESRB
AO','AO','AO - Adult Only: Contains content that is suitable
only for adults. Titles in this category may include prolonged
scenes of intense violence and/or graphic sexual content and
nudity.'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO common_lookup VALUES
( common_lookup_s1.nextval,'ITEM','ITEM_RATING','ESRB
RP','RP','RP - Rating Pending: Product has been submitted to
the ESRB and is awaiting final rating (prior to product release).'
, 1, SYSDATE, 1, SYSDATE);
INSERT INTO COMMON_LOOKUP VALUES
( common_lookup_s1.nextval, 'TRANSACTION',
'TRANSACTION_TYPE', 'DEBIT', 'DB', 'Debit', 1, SYSDATE,
1, SYSDATE);
INSERT INTO COMMON_LOOKUP VALUES
( common_lookup_s1.nextval, 'TRANSACTION',
'TRANSACTION_TYPE', 'CREDIT', 'CR', 'Credit', 1,
SYSDATE, 1, SYSDATE);
26. ( common_lookup_s1.nextval, 'RENTAL_ITEM',
'RENTAL_ITEM_TYPE', '1-DAY RENTAL', '', '1-Day Rental',
1, SYSDATE, 1, SYSDATE);
INSERT INTO COMMON_LOOKUP VALUES
( common_lookup_s1.nextval, 'RENTAL_ITEM',
'RENTAL_ITEM_TYPE', '3-DAY RENTAL', '', '3-Day Rental',
1, SYSDATE, 1, SYSDATE);
INSERT INTO COMMON_LOOKUP VALUES
( common_lookup_s1.nextval, 'RENTAL_ITEM',
'RENTAL_ITEM_TYPE', '5-DAY RENTAL', '', '5-Day Rental',
1, SYSDATE, 1, SYSDATE);
-- Format and query output.
--COLUMN common_lookup_id FORMAT 9999 HEADING
"Lookup|ID #"
--COLUMN common_lookup_table FORMAT A18 HEADING
"Lookup|Table"
--COLUMN common_lookup_column FORMAT A20
HEADING "Lookup|Column"
--COLUMN common_lookup_type FORMAT A18 HEADING
"Lookup|Type"
27. --COLUMN common_lookup_code FORMAT A8 HEADING
"Lookup|Code"
--SELECT common_lookup_id
--, common_lookup_table
--, common_lookup_column
--, common_lookup_type
--, common_lookup_code
--FROM common_lookup;
ALTER TABLE system_user ADD CONSTRAINT
fk_system_user_3 FOREIGN KEY(system_user_type)
REFERENCES common_lookup(common_lookup_id);
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'MEMBER') LOOP
28. EXECUTE IMMEDIATE 'DROP TABLE member CASCADE
CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'MEMBER_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE member_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create MEMBER table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE member
( member_id NUMBER CONSTRAINT
pk_member PRIMARY KEY
, member_type NUMBER CONSTRAINT
nn_member_1 NOT NULL
29. , account_number VARCHAR2(10) CONSTRAINT
nn_member_2 NOT NULL
, credit_card_number VARCHAR2(19) CONSTRAINT
nn_member_3 NOT NULL
, credit_card_type NUMBER CONSTRAINT
nn_member_4 NOT NULL
, created_by NUMBER CONSTRAINT
nn_member_5 NOT NULL
, creation_date DATE CONSTRAINT
nn_member_6 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_member_7 NOT NULL
, last_update_date DATE CONSTRAINT
nn_member_8 NOT NULL
, CONSTRAINT fk_member_1 FOREIGN
KEY(member_type)
REFERENCES common_lookup(common_lookup_id)
, CONSTRAINT fk_member_2 FOREIGN
KEY(credit_card_type)
REFERENCES common_lookup(common_lookup_id)
, CONSTRAINT fk_member_3 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
30. , CONSTRAINT fk_member_4 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE SEQUENCE member_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'CONTACT') LOOP
EXECUTE IMMEDIATE 'DROP TABLE contact CASCADE
CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'CONTACT_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE contact_s1';
END LOOP;
31. END;
/
-- ------------------------------------------------------------------
-- Create CONTACT table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE contact
( contact_id NUMBER CONSTRAINT
pk_contact PRIMARY KEY
, member_id NUMBER CONSTRAINT
nn_contact_1 NOT NULL
, contact_type NUMBER CONSTRAINT
nn_contact_2 NOT NULL
, last_name VARCHAR2(20) CONSTRAINT
nn_contact_3 NOT NULL
, first_name VARCHAR2(20) CONSTRAINT
nn_contact_4 NOT NULL
, middle_name VARCHAR2(20)
, created_by NUMBER CONSTRAINT
nn_contact_5 NOT NULL
32. , creation_date DATE CONSTRAINT
nn_contact_6 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_contact_7 NOT NULL
, last_update_date DATE CONSTRAINT
nn_contact_8 NOT NULL
, CONSTRAINT fk_contact_1 FOREIGN
KEY(member_id)
REFERENCES member(member_id)
, CONSTRAINT fk_contact_2 FOREIGN
KEY(contact_type)
REFERENCES common_lookup(common_lookup_id)
, CONSTRAINT fk_contact_3 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_contact_4 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE INDEX contact_n1 ON contact(member_id);
33. CREATE SEQUENCE contact_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'ADDRESS') LOOP
EXECUTE IMMEDIATE 'DROP TABLE address CASCADE
CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'ADDRESS_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE address_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
34. -- Create ADDRESS table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE address
( address_id NUMBER CONSTRAINT
pk_address PRIMARY KEY
, contact_id NUMBER CONSTRAINT
nn_address_1 NOT NULL
, address_type NUMBER CONSTRAINT
nn_address_2 NOT NULL
, city VARCHAR2(30) CONSTRAINT
nn_address_3 NOT NULL
, state_province VARCHAR2(30) CONSTRAINT
nn_address_4 NOT NULL
, postal_code VARCHAR2(20) CONSTRAINT
nn_address_5 NOT NULL
, created_by NUMBER CONSTRAINT
nn_address_6 NOT NULL
, creation_date DATE CONSTRAINT
nn_address_7 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_address_8 NOT NULL
35. , last_update_date DATE CONSTRAINT
nn_address_9 NOT NULL
, CONSTRAINT fk_address_1 FOREIGN
KEY(contact_id)
REFERENCES contact(contact_id)
, CONSTRAINT fk_address_2 FOREIGN
KEY(address_type)
REFERENCES common_lookup(common_lookup_id)
, CONSTRAINT fk_address_3 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_address_4 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE INDEX address_n1 ON address(contact_id);
CREATE SEQUENCE address_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
36. FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'STREET_ADDRESS') LOOP
EXECUTE IMMEDIATE 'DROP TABLE street_address
CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'STREET_ADDRESS_S1')
LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE
street_address_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create STREET_ADDRESS table and sequence and seed data.
-- ------------------------------------------------------------------
37. CREATE TABLE street_address
( street_address_id NUMBER CONSTRAINT
pk_st_address PRIMARY KEY
, address_id NUMBER CONSTRAINT
nn_st_address_1 NOT NULL
, line_number NUMBER CONSTRAINT
nn_st_address_2 NOT NULL
, street_address VARCHAR2(30) CONSTRAINT
nn_st_address_3 NOT NULL
, created_by NUMBER CONSTRAINT
nn_st_address_4 NOT NULL
, creation_date DATE CONSTRAINT
nn_st_address_5 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_st_address_6 NOT NULL
, last_update_date DATE CONSTRAINT
nn_st_address_7 NOT NULL
, CONSTRAINT fk_st_address_1 FOREIGN
KEY(address_id)
REFERENCES address(address_id)
, CONSTRAINT fk_st_address_2 FOREIGN
KEY(created_by)
38. REFERENCES system_user(system_user_id)
, CONSTRAINT fk_st_address_3 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE SEQUENCE street_address_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'TELEPHONE') LOOP
EXECUTE IMMEDIATE 'DROP TABLE telephone
CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'TELEPHONE_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE telephone_s1';
39. END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create TELEPHONE table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE telephone
( telephone_id NUMBER CONSTRAINT
pk_telephone PRIMARY KEY
, contact_id NUMBER CONSTRAINT
nn_telephone_1 NOT NULL
, address_id NUMBER CONSTRAINT
nn_telephone_2 NOT NULL
, telephone_type NUMBER CONSTRAINT
nn_telephone_3 NOT NULL
, country_code VARCHAR2(3) CONSTRAINT
nn_telephone_4 NOT NULL
, area_code VARCHAR2(6) CONSTRAINT
nn_telephone_5 NOT NULL
40. , telephone_number VARCHAR2(10) CONSTRAINT
nn_telephone_6 NOT NULL
, created_by NUMBER CONSTRAINT
nn_telephone_7 NOT NULL
, creation_date DATE CONSTRAINT
nn_telephone_8 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_telephone_9 NOT NULL
, last_update_date DATE CONSTRAINT
nn_telephone_10 NOT NULL
, CONSTRAINT fk_telephone_1 FOREIGN
KEY(contact_id)
REFERENCES contact(contact_id)
, CONSTRAINT fk_telephone_2 FOREIGN
KEY(telephone_type)
REFERENCES common_lookup(common_lookup_id)
, CONSTRAINT fk_telephone_3 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_telephone_4 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
41. CREATE INDEX telephone_n1 ON
telephone(contact_id,address_id);
CREATE INDEX telephone_n2 ON telephone(address_id);
CREATE SEQUENCE telephone_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'RENTAL') LOOP
EXECUTE IMMEDIATE 'DROP TABLE rental CASCADE
CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'RENTAL_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE rental_s1';
42. END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create RENTAL table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE rental
( rental_id NUMBER CONSTRAINT pk_rental
PRIMARY KEY
, customer_id NUMBER CONSTRAINT
nn_rental_1 NOT NULL
, check_out_date DATE CONSTRAINT
nn_rental_2 NOT NULL
, return_date DATE CONSTRAINT
nn_rental_3 NOT NULL
, created_by NUMBER CONSTRAINT
nn_rental_4 NOT NULL
, creation_date DATE CONSTRAINT
nn_rental_5 NOT NULL
43. , last_updated_by NUMBER CONSTRAINT
nn_rental_6 NOT NULL
, last_update_date DATE CONSTRAINT
nn_rental_7 NOT NULL
, CONSTRAINT fk_rental_1 FOREIGN
KEY(customer_id)
REFERENCES contact(contact_id)
, CONSTRAINT fk_rental_2 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_rental_3 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE SEQUENCE rental_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
44. WHERE table_name = 'ITEM') LOOP
EXECUTE IMMEDIATE 'DROP TABLE item CASCADE
CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'ITEM_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE item_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create ITEM table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE item
( item_id NUMBER CONSTRAINT pk_item
PRIMARY KEY
45. , item_barcode VARCHAR2(20) CONSTRAINT
nn_item_1 NOT NULL
, item_type NUMBER CONSTRAINT
nn_item_2 NOT NULL
, item_title VARCHAR2(60) CONSTRAINT
nn_item_3 NOT NULL
, item_subtitle VARCHAR2(60)
, item_desc CLOB CONSTRAINT nn_item_4
NOT NULL
, item_photo BFILE
, item_rating VARCHAR2(8) CONSTRAINT
nn_item_5 NOT NULL
, item_rating_agency VARCHAR2(4) CONSTRAINT
nn_item_6 NOT NULL
, item_release_date DATE CONSTRAINT
nn_item_7 NOT NULL
, created_by NUMBER CONSTRAINT
nn_item_8 NOT NULL
, creation_date DATE CONSTRAINT nn_item_9
NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_item_10 NOT NULL
, last_update_date DATE CONSTRAINT
nn_item_11 NOT NULL
46. , CONSTRAINT fk_item_1 FOREIGN
KEY(item_type)
REFERENCES common_lookup(common_lookup_id)
, CONSTRAINT fk_item_2 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_item_3 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE SEQUENCE item_s1 START WITH 1000;
-- ------------------------------------------------------------------
-- Create ITEM table triggers for content reference column.
-- ------------------------------------------------------------------
-- Check for valid rating in COMMON_LOOKUP table.
CREATE OR REPLACE TRIGGER item_t1
BEFORE INSERT OR UPDATE OF item_rating ON item
47. FOR EACH ROW
DECLARE
-- Declare guard variable.
found BOOLEAN := FALSE;
-- Declare dynamic cursor.
CURSOR get_ratings
( code VARCHAR2 ) IS
SELECT common_lookup_code
FROM common_lookup
WHERE common_lookup_table = 'ITEM'
AND common_lookup_column = 'ITEM_RATING'
AND common_lookup_code = code;
-- Define and set user-defined error.
bad_rating EXCEPTION;
48. PRAGMA EXCEPTION_INIT(bad_rating,-20101);
BEGIN
-- Check for valid rating.
FOR i IN get_ratings(:new.item_rating) LOOP
found := TRUE;
END LOOP;
-- Raise exception for invalid rating.
IF NOT found THEN
RAISE_APPLICATION_ERROR(-20101,'Rating Value not
defined in COMMON_LOOKUP table.');
END IF;
END item_t1;
/
-- Conditionally drop objects.
49. BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'RENTAL_ITEM') LOOP
EXECUTE IMMEDIATE 'DROP TABLE rental_item
CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'RENTAL_ITEM_S1')
LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE
rental_item_s1';
END LOOP;
END;
/
-- Check for valid rating agency in COMMON_LOOKUP table.
CREATE OR REPLACE TRIGGER item_t1
50. BEFORE INSERT OR UPDATE OF item_rating_agency ON
item
FOR EACH ROW
DECLARE
-- Declare guard variable.
found BOOLEAN := FALSE;
-- Declare dynamic cursor.
CURSOR get_ratings
( agency VARCHAR2 ) IS
SELECT common_lookup_code
FROM common_lookup
WHERE common_lookup_table = 'ITEM'
AND common_lookup_column =
'ITEM_RATING_AGENCY'
AND common_lookup_code = agency;
51. -- Define and set user-defined error.
bad_rating EXCEPTION;
PRAGMA EXCEPTION_INIT(bad_rating,-20102);
BEGIN
-- Check for valid rating.
FOR i IN get_ratings(:new.item_rating_agency) LOOP
found := TRUE;
END LOOP;
-- Raise exception for invalid rating.
IF NOT found THEN
RAISE_APPLICATION_ERROR(-20102,'Rating Agency
Value not defined in COMMON_LOOKUP table.');
END IF;
END item_t1;
/
52. -- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'RENTAL_ITEM') LOOP
EXECUTE IMMEDIATE 'DROP TABLE rental_item
CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'RENTAL_ITEM_S1')
LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE
rental_item_s1';
END LOOP;
END;
/
53. -- ------------------------------------------------------------------
-- Create RENTAL_ITEM table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE rental_item
( rental_item_id NUMBER CONSTRAINT
pk_rental_item PRIMARY KEY
, rental_id NUMBER CONSTRAINT
nn_rental_item_1 NOT NULL
, item_id NUMBER CONSTRAINT
nn_rental_item_2 NOT NULL
, rental_item_price NUMBER CONSTRAINT
nn_rental_item_3 NOT NULL
, rental_item_type NUMBER CONSTRAINT
nn_rental_item_4 NOT NULL
, created_by NUMBER CONSTRAINT
nn_rental_item_5 NOT NULL
, creation_date DATE CONSTRAINT
nn_rental_item_6 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_rental_item_7 NOT NULL
, last_update_date DATE CONSTRAINT
nn_rental_item_8 NOT NULL
54. , CONSTRAINT fk_rental_item_1 FOREIGN
KEY(rental_id)
REFERENCES rental(rental_id)
, CONSTRAINT fk_rental_item_2 FOREIGN
KEY(item_id)
REFERENCES item(item_id)
, CONSTRAINT fk_rental_item_3 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_rental_item_4 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE SEQUENCE rental_item_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'PRICE') LOOP
55. EXECUTE IMMEDIATE 'DROP TABLE price CASCADE
CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'PRICE_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE price_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create PRICE table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE price
( price_id NUMBER CONSTRAINT pk_price
PRIMARY KEY
, item_id NUMBER CONSTRAINT
56. nn_price_1 NOT NULL
, price_type NUMBER CONSTRAINT
nn_price_2 NOT NULL
, active_flag VARCHAR2(1) CONSTRAINT
nn_price_3 NOT NULL
, amount NUMBER CONSTRAINT
nn_price_4 NOT NULL
, start_date DATE CONSTRAINT nn_price_5
NOT NULL
, end_date DATE
, created_by NUMBER CONSTRAINT
nn_price_6 NOT NULL
, creation_date DATE CONSTRAINT
nn_price_7 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_price_8 NOT NULL
, last_update_date DATE CONSTRAINT
nn_price_9 NOT NULL
, CONSTRAINT fk_price_1 FOREIGN
KEY(item_id)
REFERENCES item(item_id)
, CONSTRAINT fk_price_2 FOREIGN
KEY(price_type)
59. SELECT common_lookup_s1.nextval -- 1
(id)
, 'PRICE' -- 2 (table)
, 'AMOUNT' -- 3 (column)
, il.type -- 4 (type)
, TO_CHAR(il.fabricated) -- 5 (code)
, il.meaning -- 6 (meaning)
, 1 -- 7 (c_id)
, SYSDATE -- 8 (c_date)
, 1 -- 9 (u_id)
, SYSDATE -- 10 (u_date)
FROM dual CROSS JOIN (SELECT 'New' AS status
, 1 AS fabricated
, '1-DAY RENTAL' type
, '1-Day Rental' meaning FROM dual
UNION ALL
SELECT 'New' AS type
, 3 AS fabricated
, '3-DAY RENTAL' type
60. , '3-Day Rental' meaning FROM dual
UNION ALL
SELECT 'New' AS type
, 5 AS fabricated
, '5-DAY RENTAL' type
, '5-Day Rental' meaning FROM dual) il;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'TRANSACTION') LOOP
EXECUTE IMMEDIATE 'DROP TABLE transaction
CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'TRANSACTION_S1')
LOOP
61. EXECUTE IMMEDIATE 'DROP SEQUENCE
transaction_s1';
END LOOP;
END;
/
-- ------------------------------------------------------------------
-- Create TRANSACTION table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE transaction
( transaction_id NUMBER CONSTRAINT
pk_transaction PRIMARY KEY
, transaction_account VARCHAR2(20) CONSTRAINT
nn_transaction_1 NOT NULL
, transaction_type NUMBER CONSTRAINT
nn_transaction_2 NOT NULL
, transaction_date DATE CONSTRAINT
nn_transaction_3 NOT NULL
, transaction_amount NUMBER CONSTRAINT
nn_transaction_4 NOT NULL
62. , rental_id NUMBER CONSTRAINT
nn_transaction_5 NOT NULL
, payment_method NUMBER CONSTRAINT
nn_transaction_6 NOT NULL
, payment_account_number VARCHAR2(20)
CONSTRAINT nn_transaction_7 NOT NULL
, created_by NUMBER CONSTRAINT
nn_transaction_8 NOT NULL
, creation_date DATE CONSTRAINT
nn_transaction_9 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_transaction_10 NOT NULL
, last_update_date DATE CONSTRAINT
nn_transaction_11 NOT NULL
, CONSTRAINT fk_transaction_1 FOREIGN
KEY(rental_id)
REFERENCES rental(rental_id)
, CONSTRAINT fk_transaction_2 FOREIGN
KEY(transaction_type)
REFERENCES common_lookup(common_lookup_id)
, CONSTRAINT fk_transaction_3 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
63. , CONSTRAINT fk_transaction_4 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE SEQUENCE transaction_s1 START WITH 1000;
-- Conditionally drop objects.
BEGIN
FOR i IN (SELECT null
FROM user_tables
WHERE table_name = 'CALENDAR') LOOP
EXECUTE IMMEDIATE 'DROP TABLE calendar CASCADE
CONSTRAINTS';
END LOOP;
FOR i IN (SELECT null
FROM user_sequences
WHERE sequence_name = 'CALENDAR_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE calendar_s1';
END LOOP;
64. END;
/
-- ------------------------------------------------------------------
-- Create CALENDAR table and sequence and seed data.
-- ------------------------------------------------------------------
CREATE TABLE calendar
( calendar_id NUMBER CONSTRAINT
pk_calendar PRIMARY KEY
, calendar_month_name VARCHAR2(3) CONSTRAINT
nn_calendar_1 NOT NULL
, calendar_full_month_name VARCHAR2(9) CONSTRAINT
nn_calendar_2 NOT NULL
, start_date DATE CONSTRAINT
nn_calendar_3 NOT NULL
, end_date DATE CONSTRAINT
nn_calendar_4 NOT NULL
, created_by NUMBER CONSTRAINT
nn_calendar_5 NOT NULL
, creation_date DATE CONSTRAINT
65. nn_calendar_6 NOT NULL
, last_updated_by NUMBER CONSTRAINT
nn_calendar_7 NOT NULL
, last_update_date DATE CONSTRAINT
nn_calendar_8 NOT NULL
, CONSTRAINT fk_calendar_1 FOREIGN
KEY(created_by)
REFERENCES system_user(system_user_id)
, CONSTRAINT fk_calendar_2 FOREIGN
KEY(last_updated_by)
REFERENCES system_user(system_user_id));
CREATE SEQUENCE calendar_s1 START WITH 1000;
-- Seed the Calendar table.
DECLARE
-- Define local variables.
start_date DATE;
end_date DATE;
66. -- Define local array types.
TYPE number_list IS TABLE OF NUMBER;
TYPE month_list IS TABLE OF VARCHAR2(3);
TYPE name_list IS TABLE OF VARCHAR2(9);
-- Define and initialize array for month ending date.
end_day NUMBER_LIST := number_list(31,28,31
,30,31,30
,31,31,30
,31,30,31);
-- Define and initial short and long month names.
months MONTH_LIST := month_list('JAN','FEB','MAR'
,'APR','MAY','JUN'
,'JUL','AUG','SEP'
,'OCT','NOV','DEC');
month_names NAME_LIST :=
name_list('January','February','March'
73. , creation_date
, last_updated_by
, last_update_date)
VALUES
( 5,'DBA', 2, 1,'Fullerton','Gail', 1, SYSDATE, 1, SYSDATE);
-- ------------------------------------------------------------------
-- This seeds rows in a dependency chain, including the
MEMBER, CONTACT
-- ADDRESS, and TELEPHONE tables.
-- ------------------------------------------------------------------
-- Insert record set #1.
-- ------------------------------------------------------------------
SELECT 'INSERT MEMBER, CONTACT, ADDRESS, ETC' AS
"Section Header" FROM dual;
INSERT INTO member VALUES
( member_s1.nextval
,(SELECT common_lookup_id
74. FROM common_lookup
WHERE common_lookup_table = 'MEMBER'
AND common_lookup_column = 'MEMBER_TYPE'
AND common_lookup_type = 'GROUP')
,'B293-71445'
,'1111-2222-3333-4444'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'MEMBER'
AND common_lookup_column = 'CREDIT_CARD_TYPE'
AND common_lookup_type = 'DISCOVER_CARD')
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO contact
( contact_id
, member_id
, contact_type
, first_name
75. , middle_name
, last_name
, created_by
, creation_date
, last_updated_by
, last_update_date )
VALUES
( contact_s1.nextval
, member_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'CONTACT'
AND common_lookup_column = 'CONTACT_TYPE'
AND common_lookup_type = 'CUSTOMER')
,'Randi','','Winn'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO address VALUES
76. ( address_s1.nextval
, contact_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'ADDRESS'
AND common_lookup_column = 'ADDRESS_TYPE'
AND common_lookup_type = 'HOME')
,'San Jose','CA','95192'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO street_address VALUES
( street_address_s1.nextval
, address_s1.currval
, 1
,'10 El Camino Real'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO telephone VALUES
77. ( telephone_s1.nextval
, address_s1.currval
, contact_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'TELEPHONE'
AND common_lookup_column = 'TELEPHONE_TYPE'
AND common_lookup_type = 'HOME')
,'USA','408','111-1111'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO contact
( contact_id
, member_id
, contact_type
, first_name
, middle_name
, last_name
78. , created_by
, creation_date
, last_updated_by
, last_update_date )
VALUES
( contact_s1.nextval
, member_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'CONTACT'
AND common_lookup_column = 'CONTACT_TYPE'
AND common_lookup_type = 'CUSTOMER')
,'Brian','','Winn'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO address VALUES
( address_s1.nextval
, contact_s1.currval
79. ,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'ADDRESS'
AND common_lookup_column = 'ADDRESS_TYPE'
AND common_lookup_type = 'HOME')
,'San Jose','CA','95192'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO street_address VALUES
( street_address_s1.nextval
, address_s1.currval
, 1
,'10 El Camino Real'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO telephone VALUES
( telephone_s1.nextval
, address_s1.currval
80. , contact_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'TELEPHONE'
AND common_lookup_column = 'TELEPHONE_TYPE'
AND common_lookup_type = 'HOME')
,'USA','408','111-1111'
, 2, SYSDATE, 2, SYSDATE);
-- ------------------------------------------------------------------
-- Insert record set #2.
-- ------------------------------------------------------------------
INSERT INTO member VALUES
( member_s1.nextval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'MEMBER'
AND common_lookup_column = 'MEMBER_TYPE'
81. AND common_lookup_type = 'GROUP')
,'B293-71446'
,'2222-3333-4444-5555'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'MEMBER'
AND common_lookup_column = 'CREDIT_CARD_TYPE'
AND common_lookup_type = 'DISCOVER_CARD')
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO contact
( contact_id
, member_id
, contact_type
, first_name
, middle_name
, last_name
, created_by
82. , creation_date
, last_updated_by
, last_update_date )
VALUES
( contact_s1.nextval
, member_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'CONTACT'
AND common_lookup_column = 'CONTACT_TYPE'
AND common_lookup_type = 'CUSTOMER')
,'Oscar','','Vizquel'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO address VALUES
( address_s1.nextval
, contact_s1.currval
,(SELECT common_lookup_id
83. FROM common_lookup
WHERE common_lookup_table = 'ADDRESS'
AND common_lookup_column = 'ADDRESS_TYPE'
AND common_lookup_type = 'HOME')
,'San Jose','CA','95192'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO street_address VALUES
( street_address_s1.nextval
, address_s1.currval
, 1
,'12 El Camino Real'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO telephone VALUES
( telephone_s1.nextval
, address_s1.currval
, contact_s1.currval
84. ,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'TELEPHONE'
AND common_lookup_column = 'TELEPHONE_TYPE'
AND common_lookup_type = 'HOME')
,'USA','408','222-2222'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO contact
( contact_id
, member_id
, contact_type
, first_name
, middle_name
, last_name
, created_by
, creation_date
, last_updated_by
85. , last_update_date )
VALUES
( contact_s1.nextval
, member_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'CONTACT'
AND common_lookup_column = 'CONTACT_TYPE'
AND common_lookup_type = 'CUSTOMER')
,'Doreen','','Vizquel'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO address VALUES
( address_s1.nextval
, contact_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'ADDRESS'
86. AND common_lookup_column = 'ADDRESS_TYPE'
AND common_lookup_type = 'HOME')
,'San Jose','CA','95192'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO street_address VALUES
( street_address_s1.nextval
, address_s1.currval
, 1
,'12 El Camino Real'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO telephone VALUES
( telephone_s1.nextval
, address_s1.currval
, contact_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
87. WHERE common_lookup_table = 'TELEPHONE'
AND common_lookup_column = 'TELEPHONE_TYPE'
AND common_lookup_type = 'HOME')
,'USA','408','222-2222'
, 2, SYSDATE, 2, SYSDATE);
-- ------------------------------------------------------------------
-- Insert record set #3.
-- ------------------------------------------------------------------
INSERT INTO member VALUES
( member_s1.nextval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'MEMBER'
AND common_lookup_column = 'MEMBER_TYPE'
AND common_lookup_type = 'GROUP')
,'B293-71447'
88. ,'3333-4444-5555-6666'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'MEMBER'
AND common_lookup_column = 'CREDIT_CARD_TYPE'
AND common_lookup_type = 'DISCOVER_CARD')
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO contact
( contact_id
, member_id
, contact_type
, first_name
, middle_name
, last_name
, created_by
, creation_date
, last_updated_by
89. , last_update_date )
VALUES
( contact_s1.nextval
, member_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'CONTACT'
AND common_lookup_column = 'CONTACT_TYPE'
AND common_lookup_type = 'CUSTOMER')
,'Meaghan','','Sweeney'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO address VALUES
( address_s1.nextval
, contact_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'ADDRESS'
90. AND common_lookup_column = 'ADDRESS_TYPE'
AND common_lookup_type = 'HOME')
,'San Jose','CA','95192'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO street_address VALUES
( street_address_s1.nextval
, address_s1.currval
, 1
,'14 El Camino Real'
, 2, SYSDATE, 2, SYSDATE);
INSERT INTO telephone VALUES
( telephone_s1.nextval
, address_s1.currval
, contact_s1.currval
,(SELECT common_lookup_id
FROM common_lookup
105. ( item_s1.nextval
,'ASIN: 6304916558'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Tomorrow Never Dies'
,''
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'13-MAY-1998'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00000K0EA'
,(SELECT common_lookup_id
106. FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Tomorrow Never Dies'
,'Special Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'22-OCT-2002'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: 6305784922'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The World Is Not Enough'
107. ,''
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'16-MAY-2000'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000NIBURQ'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The World Is Not Enough'
,''
, empty_clob()
, NULL
111. FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Christmas Carol'
,''
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'05-OCT-1999'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0000AQS5D'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Scrooge'
112. ,''
, empty_clob()
, NULL
,'G'
,'MPAA'
,'23-SEP-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: 6305127719'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Clear and Present Danger'
,''
, empty_clob()
, NULL
113. ,'PG-13'
,'MPAA'
,'21-OCT-1998'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00008K76V'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Clear and Present Danger'
,'Special Collector''s Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'06-MAY-2003'
114. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00003CXI1'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Harry Potter and the Sorcer''s Stone'
,'Two-Disc Special Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'28-MAY-2002'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
115. ( item_s1.nextval
,'ASIN: B000062TU1'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Harry Potter and the Sorcer''s Stone'
,'Full Screen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'28-MAY-2002'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00008DDXC'
,(SELECT common_lookup_id
116. FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Harry Potter and the Chamber of Secrets'
,'Two-Disc Special Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'11-APR-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00008DDXL'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Harry Potter and the Chamber of Secrets'
117. ,'Full Screen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'11-APR-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00005JMAH'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Harry Potter and the Prisoner of Azkaban'
,'Two-Disc Special Edition'
, empty_clob()
, NULL
118. ,'PG'
,'MPAA'
,'23-NOV-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0002TT0NW'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Harry Potter and the Prisoner of Azkaban'
,'2-Disc Full Screen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'23-NOV-2004'
119. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0002VB24K'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Harry Potter and the Chamber of Secrets'
,''
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'23-NOV-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
120. ( item_s1.nextval
,'ASIN: B000E6EK2Y'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Harry Potter and the Goblet of Fire'
,'Widescreen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'07-MAR-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000E6EK38'
,(SELECT common_lookup_id
121. FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Harry Potter and the Goblet of Fire'
,'Full Screen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'07-MAR-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000E6EK3S'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Harry Potter and the Goblet of Fire'
122. ,'Two-Disc Special Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'07-MAR-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000E6EZ3Z'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Harry Potter and the Order of the Phoenix'
,'Widescreen Edition'
, empty_clob()
, NULL
123. ,'PG-13'
,'MPAA'
,'11-DEC-2007'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: 6305182043'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Hunt for Red October'
,''
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'01-DEC-1998'
124. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00008K76U'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Hunt for Red October'
,'Special Collector''s Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'06-MAY-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
125. ( item_s1.nextval
,'ASIN: B0002YLCG0'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'King Arthur - The Director''s Cut'
,'Wide Screen Edition'
, empty_clob()
, NULL
,'R'
,'MPAA'
,'21-DEC-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0002YLCFQ'
,(SELECT common_lookup_id
126. FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'King Arthur'
,'PG-13 Full Screen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'21-DEC-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0002YLCG0'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'King Arthur - The Director''s Cut'
127. ,'Wide Screen Edition'
, empty_clob()
, NULL
,'R'
,'MPAA'
,'21-DEC-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00003CWT6'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Lord of the Rings - Fellowship of the Ring'
,'Widescreen Edition'
, empty_clob()
, NULL
128. ,'PG-13'
,'MPAA'
,'06-AUG-2002'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000065U3Q'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'The Lord of the Rings - Fellowship of the Ring'
,'Fullscreen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'06-AUG-2002'
129. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000067DNF'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Lord of the Rings - Fellowship of the Ring'
,'Platinum Series Special Extended Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'12-NOV-2002'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
130. ( item_s1.nextval
,'ASIN: B00005JKZV'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Lord of the Rings - Two Towers'
,'Widescreen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'26-AUG-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00009APK1'
,(SELECT common_lookup_id
131. FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'The Lord of the Rings - Two Towers'
,'Fullscreen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'26-AUG-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00009TB5G'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Lord of the Rings - Two Towers'
132. ,'Platinum Series Special Extended Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'18-NOV-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00005JKZY'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Lord of the Rings - The Return of the King'
,'Widescreen Edition'
, empty_clob()
, NULL
133. ,'PG-13'
,'MPAA'
,'25-MAY-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0001US8E4'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'The Lord of the Rings - The Return of the King'
,'Fullscreen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'25-MAY-2004'
134. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000634DCW'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Lord of the Rings - The Return of the King'
,'Platinum Series Special Extended Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'14-DEC-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
136. FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Patriot Games'
,'Special Collector''s Edition'
, empty_clob()
, NULL
,'R'
,'MPAA'
,'06-MAY-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00005JM5E'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Pirates of the Caribbean - The Curse of the Black Pearl'
137. ,'Two-Disc Collector''s Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'02-DEC-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0002XL342'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Pirates of the Caribbean - The Curse of the Black Pearl'
,'Three-Disc Special Edition'
, empty_clob()
, NULL
138. ,'PG-13'
,'MPAA'
,'02-NOV-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0000C6DWS'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Pirates of the Caribbean - The Curse of the Black Pearl'
,''
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'02-DEC-2003'
139. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000I0RQVI'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Pirates of the Caribbean - Dead Man''s Chest'
,''
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'05-DEC-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
140. ( item_s1.nextval
,'ASIN: B00005JP0F'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Pirates of the Caribbean - Dead Man''s Chest'
,'Two-Disc Collector''s Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'05-DEC-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0R0I0RDEI'
,(SELECT common_lookup_id
141. FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Pirates of the Caribbean - At World''s End'
,''
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'05-DEC-2007'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0R0I0RRES'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Pirates of the Caribbean - At World''s End'
142. ,'Two-Disc Collector''s Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'05-DEC-2007'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00009Q98M'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Indiana Jones and the Raiders of the Lost Ark'
,'Widescreen Edition'
, empty_clob()
, NULL
143. ,'PG'
,'MPAA'
,'20-FEB-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000F21K66'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Indiana Jones and the Raiders of the Lost Ark'
,'Fullscreen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'20-FEB-2003'
144. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000F7OMZ2'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Indiana Jones and the Temple of Doom'
,'Widescreen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'20-FEB-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
145. ( item_s1.nextval
,'ASIN: B000F7OMZ3'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Indiana Jones and the Temple of Doom'
,'Fullscreen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'20-FEB-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000F7OPCC'
,(SELECT common_lookup_id
146. FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Indiana Jones and the Last Crusade'
,'Widescreen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'20-FEB-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000F7OPCR'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Indiana Jones and the Last Crusade'
147. ,'Fullscreen Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'20-FEB-2003'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00005JKCH'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Spider-Man'
,'Widescreen Special Edition'
, empty_clob()
, NULL
148. ,'PG-13'
,'MPAA'
,'01-NOV-2002'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00006F2TV'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Spider-Man'
,'Fullscreen Special Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'01-NOV-2002'
149. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00005JMQW'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Spider-Man 2'
,'Widescreen Special Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'30-NOV-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
150. ( item_s1.nextval
,'ASIN: B0002XK186'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Spider-Man 2'
,'Fullscreen Special Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'30-NOV-2004'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: C00005JMQW'
,(SELECT common_lookup_id
151. FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Spider-Man 3'
,'Widescreen Special Edition'
, empty_clob()
, NULL
,'PG-13'
,'MPAA'
,'30-NOV-2007'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: CB0002XK186'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Spider-Man 3'
160. ( item_s1.nextval
,'ASIN: B00076SCPW'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Star Wars - Episode VI'
,'Return of the Jedi'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'12-AUG-2005'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00276LJKZ'
,(SELECT common_lookup_id
161. FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Star Wars - Episode VI'
,'Return of the Jedi'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'12-AUG-2005'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00005JL8F'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'The Sum of All Fears'
164. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000068TPN'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'We Were Soldiers'
,''
, empty_clob()
, NULL
,'R'
,'MPAA'
,'20-AUG-2002'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
165. ( item_s1.nextval
,'ASIN: B000E8M0VA'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'DVD_WIDE_SCREEN')
,'Chronicles of Narnia - The Lion, the Witch and the Wardrobe'
,'Widescreen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'04-APR-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00005JO1X'
,(SELECT common_lookup_id
166. FROM common_lookup
WHERE common_lookup_type = 'DVD_FULL_SCREEN')
,'Chronicles of Narnia - The Lion, the Witch and the Wardrobe'
,'Fullscreen Edition'
, empty_clob()
, NULL
,'PG'
,'MPAA'
,'04-APR-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0009EK534'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'GAMECUBE')
,'Chronicles of Narnia - The Lion, the Witch and the Wardrobe'
167. ,''
, empty_clob()
, NULL
,'T'
,'ESRB'
,'15-JUN-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0009ELZXI'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'PLAYSTATION2')
,'Chronicles of Narnia - The Lion, the Witch and the Wardrobe'
,''
, empty_clob()
, NULL
168. ,'T'
,'ESRB'
,'15-JUN-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B0009EP9DU'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'XBOX')
,'Chronicles of Narnia - The Lion, the Witch and the Wardrobe'
,''
, empty_clob()
, NULL
,'T'
,'ESRB'
,'15-JUN-2006'
169. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000930DPU'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'GAMECUBE')
,'Harry Potter: Goblet of Fire'
,''
, empty_clob()
, NULL
,'E10+'
,'ESRB'
,'15-JUN-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
171. FROM common_lookup
WHERE common_lookup_type = 'XBOX')
,'Harry Potter: Goblet of Fire'
,''
, empty_clob()
, NULL
,'E10+'
,'ESRB'
,'15-JUN-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000930DPU'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'GAMECUBE')
,'Pirates of the Caribbean'
172. ,''
, empty_clob()
, NULL
,'T'
,'ESRB'
,'15-JUN-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000FWAGNY'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'PLAYSTATION2')
,'Pirates of the Caribbean'
,'The Legend of Jack Sparrow'
, empty_clob()
, NULL
173. ,'T'
,'ESRB'
,'27-JUN-2006'
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B00008V6TF'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'XBOX')
,'Pirates of the Caribbean'
,''
, empty_clob()
, NULL
,'T'
,'ESRB'
,'22-MAY-2007'
174. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO item VALUES
( item_s1.nextval
,'ASIN: B000MK4G1M'
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_type = 'XBOX')
,'Pirates of the Caribbean'
,'At Worlds End'
, empty_clob()
, NULL
,'T'
,'ESRB'
,'22-MAY-2007'
, 3, SYSDATE, 3, SYSDATE);
-- ------------------------------------------------------------------
175. -- Inserts 5 rentals with 9 dependent rental items. This section
inserts
-- 5 rows in the RENTAL table, then 9 rows in the
RENTAL_ITEM table. The
-- inserts into the RENTAL_ITEM tables use scalar subqueries
to find the
-- proper foreign key values by querying the RENTAL table
primary keys.
-- ------------------------------------------------------------------
-- Insert 5 records in the RENTAL table.
-- ------------------------------------------------------------------
SELECT 'INSERT RENTAL' AS "Section Header" FROM dual;
INSERT INTO rental VALUES
( rental_s1.nextval
,(SELECT contact_id
FROM contact
WHERE last_name = 'Vizquel'
AND first_name = 'Oscar')
, SYSDATE, SYSDATE + 5
176. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental VALUES
( rental_s1.nextval
,(SELECT contact_id
FROM contact
WHERE last_name = 'Vizquel'
AND first_name = 'Doreen')
, SYSDATE, SYSDATE + 5
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental VALUES
( rental_s1.nextval
,(SELECT contact_id
FROM contact
WHERE last_name = 'Sweeney'
AND first_name = 'Meaghan')
, SYSDATE, SYSDATE + 5
177. , 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental VALUES
( rental_s1.nextval
,(SELECT contact_id
FROM contact
WHERE last_name = 'Sweeney'
AND first_name = 'Ian')
, SYSDATE, SYSDATE + 5
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental VALUES
( rental_s1.nextval
,(SELECT contact_id
FROM contact
WHERE last_name = 'Winn'
AND first_name = 'Brian')
, SYSDATE, SYSDATE + 5
178. , 3, SYSDATE, 3, SYSDATE);
/*
-- ------------------------------------------------------------------
-- Insert 9 records in the RENTAL_ITEM table.
-- ------------------------------------------------------------------ */
SELECT 'INSERT RENTAL_ITEM' AS "Section Header"
FROM dual;
INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
, last_updated_by
179. , last_update_date)
VALUES
( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
, contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Vizquel'
AND c.first_name = 'Oscar')
,(SELECT i.item_id
FROM item i
, common_lookup cl
WHERE i.item_title = 'Star Wars - Episode I'
AND i.item_subtitle = 'The Phantom Menace'
AND i.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
,(SELECT common_lookup_id
180. FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
, last_updated_by
, last_update_date)
VALUES
( rental_item_s1.nextval
181. ,(SELECT r.rental_id
FROM rental r inner join contact c
ON r.customer_id = c.contact_id
WHERE c.last_name = 'Vizquel'
AND c.first_name = 'Oscar')
,(SELECT d.item_id
FROM item d join common_lookup cl
ON d.item_title = 'Star Wars - Episode II'
WHERE d.item_subtitle = 'Attack of the Clones'
AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
182. INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
, last_updated_by
, last_update_date)
VALUES
( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
, contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Vizquel'
183. AND c.first_name = 'Oscar')
,(SELECT d.item_id
FROM item d
, common_lookup cl
WHERE d.item_title = 'Star Wars - Episode III'
AND d.item_subtitle = 'Revenge of the Sith'
AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental_item
( rental_item_id
184. , rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
, last_updated_by
, last_update_date)
VALUES
( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
, contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Vizquel'
AND c.first_name = 'Doreen')
,(SELECT d.item_id
FROM item d
185. , common_lookup cl
WHERE d.item_title = 'Tomorrow Never Dies'
AND d.item_subtitle IS NULL
AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
186. , rental_item_type
, created_by
, creation_date
, last_updated_by
, last_update_date)
VALUES
( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
, contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Vizquel'
AND c.first_name = 'Doreen')
,(SELECT d.item_id
FROM item d
, common_lookup cl
WHERE d.item_title = 'Around the World in 80 Days'
AND d.item_subtitle IS NULL
187. AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
188. , last_updated_by
, last_update_date)
VALUES
( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
, contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Sweeney'
AND c.first_name = 'Meaghan')
,(SELECT d.item_id
FROM item d
, common_lookup cl
WHERE d.item_title = 'The Patriot'
AND d.item_subtitle = 'Special Edition'
AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
189. ,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
, last_updated_by
, last_update_date)
VALUES
190. ( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
, contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Sweeney'
AND c.first_name = 'Ian')
,(SELECT d.item_id
FROM item d
, common_lookup cl
WHERE d.item_title = 'Spider-Man'
AND d.item_subtitle = 'Fullscreen Special Edition'
AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_FULL_SCREEN')
, 5
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
191. AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
, last_updated_by
, last_update_date)
VALUES
( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
192. , contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Winn'
AND c.first_name = 'Brian')
,(SELECT d.item_id
FROM item d
, common_lookup cl
WHERE d.item_title = 'We Were Soldiers'
AND d.item_subtitle IS NULL
AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
193. INSERT INTO rental_item
( rental_item_id
, rental_id
, item_id
, rental_item_price
, rental_item_type
, created_by
, creation_date
, last_updated_by
, last_update_date)
VALUES
( rental_item_s1.nextval
,(SELECT r.rental_id
FROM rental r
, contact c
WHERE r.customer_id = c.contact_id
AND c.last_name = 'Winn'
194. AND c.first_name = 'Brian')
,(SELECT d.item_id
FROM item d
, common_lookup cl
WHERE d.item_title = 'The Hunt for Red October'
AND d.item_subtitle = 'Special Collector''s Edition'
AND d.item_type = cl.common_lookup_id
AND cl.common_lookup_type = 'DVD_WIDE_SCREEN')
, 5
,(SELECT common_lookup_id
FROM common_lookup
WHERE common_lookup_table = 'RENTAL_ITEM'
AND common_lookup_column = 'RENTAL_ITEM_TYPE'
AND common_lookup_type = '5-DAY RENTAL')
, 3, SYSDATE, 3, SYSDATE);
-- Write all prior to program units.
COMMIT;
195. -- ----------------------------------------------
-- Create update_price_function.
-- ----------------------------------------------
SELECT 'CREATE PRICE UPDATE FUNCTION' AS "Section
Header" FROM dual;
@@update_price_function.sql
SET SERVEROUTPUT ON SIZE UNLIMITED
DECLARE
lv_count INTEGER;
BEGIN
IF update_price = 0 THEN
SELECT COUNT(*) INTO lv_count FROM price;
dbms_output.put_line('Inserted Prices ['||lv_count||']
records.');
ELSE
dbms_output.put_line('No Prices Inserted.');
196. END IF;
END;
/
BEGIN
FOR i IN (SELECT product
FROM product_component_version
WHERE REGEXP_LIKE(product,'.+11g.+')) LOOP
dbms_output.put_line('Valid ['||i.product||'].');
END LOOP;
END;
/
-- This creates a transactionally safe individual member insert
-- into the MEMBER, CONTACT, ADDRESS,
STREET_ADDRESS, and
-- TELEPHONE tables for Oracle 11g; it won't run in Oracle
10g
-- and you should use the contact_insert_10g.sql script in the
197. -- create_store.sql when working on Oracle 10g XE.
@@contact_insert.sql
@@contact_insert_10g.sql
-- Insert complete contact information using stored procedure.
-- If you're running on Oracle 10g XE, switch contact_insert to
contact_insert_10g as
-- a procedure call in the following statements.
EXECUTE contact_insert('INDIVIDUAL','R11-514-34','1111-
1111-1111-
1111','VISA_CARD','Clinton','Goeffrey','Ward','CUSTOMER','
HOME','Provo','Utah','84606','118 South 9th
East','HOME','011','801','423-1234');
EXECUTE contact_insert('INDIVIDUAL','R11-514-35','1111-
1111-1111-
1111','VISA_CARD','Brandt','Henry','Ward','CUSTOMER','HO
ME','Provo','Utah','84606','118 South 9th
East','HOME','011','801','423-1234');
EXECUTE contact_insert('INDIVIDUAL','R11-514-36','1111-
2222-1111-
1111','VISA_CARD','Wendy','Jane','Moss','CUSTOMER','HOM
E','Provo','Utah','84606','1218 South 10th
East','HOME','011','801','423-1234');
EXECUTE contact_insert('INDIVIDUAL','R11-514-37','1111-
1111-2222-
1111','VISA_CARD','Jonah','Simon','Gretelz','CUSTOMER','HO
198. ME','Provo','Utah','84606','2118 South 7th
East','HOME','011','801','423-1234');
EXECUTE contact_insert('INDIVIDUAL','R11-514-38','1111-
1111-1111-
2222','MASTER_CARD','Jane','Elizabeth','Royal','CUSTOMER',
'HOME','Provo','Utah','84606','2228 South 14th
East','HOME','011','801','423-1234');
EXECUTE contact_insert_10g('INDIVIDUAL','R11-514-
39','1111-1111-3333-
1111','VISA_CARD','Brian','Nathan','Smith','CUSTOMER','HO
ME','Spanish Fork','Utah','84606','333 North 2nd
East','HOME','011','801','423-1234');
-- Place Chapter 6 Procedure in database.
@@transaction_procedure.sql
-- Update the address table.
UPDATE address
SET state_province = 'California'
WHERE state_province = 'CA';
-- Conditionally drop table.
BEGIN
199. FOR i IN (SELECT table_name
FROM user_tables
WHERE table_name = 'AIRPORT') LOOP
EXECUTE IMMEDIATE 'DROP TABLE '||i.table_name||'
CASCADE CONSTRAINTS';
END LOOP;
FOR i IN (SELECT sequence_name
FROM user_sequences
WHERE sequence_name = 'AIRPORT_S1') LOOP
EXECUTE IMMEDIATE 'DROP SEQUENCE
'||i.sequence_name;
END LOOP;
END;
/
-- Create table.
CREATE TABLE airport
( airport_id NUMBER CONSTRAINT pk_airport
PRIMARY KEY
200. , airport_code VARCHAR2(3) CONSTRAINT nn_airport1
NOT NULL
, airport_city VARCHAR2(30) CONSTRAINT nn_airport2
NOT NULL
, city VARCHAR2(30) CONSTRAINT nn_airport3
NOT NULL
, state_province VARCHAR2(30) CONSTRAINT nn_airport4
NOT NULL
, created_by NUMBER
, creation_date DATE
, last_updated_by NUMBER
, last_update_date DATE
, CONSTRAINT fk_airport1 FOREIGN KEY (created_by)
REFERENCES system_user (system_user_id)
, CONSTRAINT fk_airport2 FOREIGN KEY (last_updated_by)
REFERENCES system_user (system_user_id));
-- Create sequence.
CREATE SEQUENCE airport_s1;