Documente Academic
Documente Profesional
Documente Cultură
com
Project Scenario:
You are a small consulting company specializing in database development. You have just been awarded the
contract to develop a data model for a database application system for a small retail store called Oracle
Baseball League (OBL).
The Oracle Baseball League store serves the entire surrounding community selling baseball kit. The OBL has
two types of customer, there are individuals who purchase items like balls, cleats, gloves, shirts, screen printed
t-shirts, and shorts. Additionally customers can represent a team when they purchase uniforms and equipment
on behalf of the team.
Teams and individual customers are free to purchase any item from the inventory list, but teams get a discount
on the list price depending on the number of players. When a customer places an order we record the order
items for that order in our database.
OBL has a team of three sales representatives that officially only call on teams but have been known to handle
individual customer complaints.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
2
In this step you will use the “obl Sports.ddl” file provided for you to create your relational database. This file
must first be extracted.
DESCRIBE customers;
4. All changes that you make in APEX are permanent changes so you do not need to save your work.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
3
Task Instructions
Use the completed table mapping document produced in a previous exercise to verify the table creation.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
4
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
5
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
6
6. How many columns are created for the price history table?
7. What statement is used to enforce the constraint that the category column of the items table must
have a value?
8. What is the name of the foreign key constraint between the customers and customer addresses tables?
9. What are the lowest and highest values that can be stored in the commission_rate column for the
sales_representatives table?
10. What are the lowest and highest values that can be stored in the price column for the price_history
table?
11. What are the 3 columns that make up the primary key for the price_history table?
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
7
Modifying a column
1. Run the DESCRIBE command on the orders table to view its structure.
2. Task: Add a default constraint that will use todays date to assign a value to the odr_date column of the
orders table if no date is provided.
3. Run the DESCRIBE command again to verify the command was successful.
Adding a column
The client has decided that they would like a separate column for the customer’s mobile phone number. This is
an optional column that will be required to store 11 digits.
1. Run the DESCRIBE command on the customers table to view its structure.
2. Task: Add column that will satisfy the clients requirements
3. Run the DESCRIBE command on the customers table to view its structure.
Dropping a column
The client has decided that they don’t need the mobile number column as most customers only provide a
single contact number and that is already catered for with the existing phone_number column.
1. Run the DESCRIBE command on the customers table to view its structure.
2. Task: Drop the column that was created to store the mobile phone number.
3. Run the DESCRIBE command on the customers table to view its structure.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
8
In this step you will populate and work with the data that is stored in the database system tables.
Loyalty
ctr First Phone Current tem sre
email Last name card
number name number balance id id
number
brianrog@hoote
c02001 Brian Rogers 01654564898 -5 lc4587
ch.com
3. This information violates the check constraint that the current balance must not be less than zero.
Change the current balance to 50 and rerun the query.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
9
In this step you will populate and work with the data that is stored in the database system.
2. Obl is going to update the price of the premium bat so you will need to write a query that will close off
the current price by adding the system date values to the end_date and end_time fields. To run this
query you will need to both match the item number and identify that the end date is null. This ensures
that you are updating the latest price.
3. Rerun the select statement on the price_history table to ensure that the statement has been executed.
4. Insert a new row that will use the current date and time to set the new price of the premium bat to be
99.99.
5. Rerun the select statement on the price_history table to ensure that the statement has been executed.
2. Run a select statement on the customers_addresses table to ensure that the statement has been
executed.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
10
In this step you will retrieve data that is stored in the database system by using a SELECT statement.
1. customers.
2. teams.
3. items
3. Display the name, description and category for every item in the table.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
11
In this step you will retrieve data that is stored in the database system by using a SELECT statement.
2. Obl is considering giving a gift card to all its customers of 5.00 that can be used to reduce their current
balance. Write a query that will show the customers first name, last name, customer number, current
balance and the value of their balance minus the gift value.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
12
In this step you will refine the data that is returned in your query by adding a WHERE clause to your SELECT
statement.
2. Display the first name, last name and customer number for all customers who have a current balance
of greater than 100. Use an appropriate alias for your column headings.
3. Display the order id, date and time of all orders that were placed before the 28th of May 2017. Use an
appropriate alias for your column headings.
Exercise 6 : Pattern Matching: Combining Wildcard Characters with the LIKE Operator
1. Display item number and name of all items that have a name that contain a lowercase o. Use an
appropriate alias for your column headings.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
13
In this step you will refine the data that is returned in your query by adding a WHERE clause to your SELECT
statement.
2. Write a query that will display information for only teams that receive a discount in the following
format:
The Rockets team has 25 players and receives a discount of 10 percent.
Use Team Information as the column alias.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
14
In this step you will sort the order of the data that is returned in your query by adding an ORDER BY clause to
the end of your SELECT statement.
1. Display the team name and number of players alphabetically in order of team name. Use an
appropriate alias for your column headings.
2. Display the team name and number of players in descending order of number of players. Use an
appropriate alias for your column headings.
3. Display the team name and number of players alphabetically in order of team name. Use Team Name
for the name alias and Players for the number of players. Sort the output in descending order of name
using the alias in the ORDER BY clause.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
15
Exercise 1 : TOP-N-ANALYSIS
1. The customers are numbered sequentially with each new customer being assigned a higher customer
number. Use TOP-N-ANALYSIS to only show the First and last name of the first three customers. Show
the customers first and last name in the same column using Customer Name as the column alias.
1. Use a substitution variable that will allow you to enter the commission rate for the sales
representatives. The first and last names should be displayed to screen for any sales representatives
that earn that commission rate and the output should be ordered by their last name. Use an
appropriate alias for your column headings.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
16
In this step you will write SELECT statements to access data from more than one table.
2. Adapt the query from the previous question to only show the id, first name, last name, address line 1,
address line 2, city, email and phone_number for the sales representatives.
2. Display all of the information about items and their price history by joining the items and price_history
tables.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
17
Write SELECT Statements Using Data From Multiple Tables Using Equijoins and Non-
Equijoins
1. Write a query that will display who the supervisor is for each of the sales representatives. The
information should be displayed in two columns, the first column will be the first name and last name
of the sales representative and the second will be the first name and last name of the supervisor. The
column aliases should be Rep and Supervisor.
1. Write a query that will display all of the team and customer information even if there is no match with
the table on the left (team).
1. Create a Cartesian product between the customer and sales representative tables.
Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.