You are on page 1of 146

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

e

yฺ
l
n
Oracle Database 12c:
o SQL
e
s
u
Workshop I

C
ฺAฺ
S
ru
eGuide
Activity
P
rtec

n

ib
C
d

r

a
sity

e
niv

U
e
l
ac

Or

D80190GC11
Edition 1.1
July 2014
D87242

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Disclaimer

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

This document contains proprietary information and is protected by copyright and other intellectual property laws. You may copy and
print this document solely for your own use in an Oracle training course. The document may not be modified or altered in any way.
Except where your use constitutes "fair use" under copyright law, you may not use, share, download, upload, copy, print, display,
perform, reproduce, publish, license, post, transmit, or distribute this document in whole or in part without the express authorization
of Oracle.
The information contained in this document is subject to change without notice. If you find any problems in the document, please
report them in writing to: Oracle University, 500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
warranted to be error-free.
Restricted Rights Notice
If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the United
States Government, the following notice is applicable:
U.S. GOVERNMENT RIGHTS
The U.S. Government’s rights to use, modify, reproduce, release, perform, display, or disclose these training materials are restricted
by the terms of the applicable Oracle license agreement and/or the applicable U.S. Government contract.
Trademark Notice
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.

e

us

ฺC

Author
Dimpi Rani Sarmah

e

ฺA
S
ru

P
c
e
t
er

y
onl

Technical Contributors and Reviewers
Nancy Greenberg, Swarnapriya Shridhar, Bryan Roberts, Laszlo Czinkoczki, KimSeong Loh,
Brent Dayley, Jim Spiller, Christopher Wensley, Manish Pawar, Clair Bennett, Yanti Chang,
Joel Goodman, Gerlinde Frenzen and Madhavi Siddireddy

ib
C
d

n

a
sity

er
v
i
n using: Oracle Tutor
This book was published
U
e
cl
a
r
O

Table of Contents

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

Practices for Lesson 1: Introduction ........................................................................................................ 1-1
Practices for Lesson 1: Overview............................................................................................................. 1-2
Practice 1-1: Introduction......................................................................................................................... 1-3
Solution 1-1: Introduction......................................................................................................................... 1-4
Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement........................................... 2-1
Practices for Lesson 2: Overview............................................................................................................. 2-2
Practice 2-1: Retrieving Data Using the SQL SELECT Statement ............................................................. 2-3
Solution 2-1: Retrieving Data Using the SQL SELECT Statement ............................................................. 2-8
Practices for Lesson 3: Restricting and Sorting Data .............................................................................. 3-1
Practices for Lesson 3: Overview............................................................................................................. 3-2
Practice 3-1: Restricting and Sorting Data................................................................................................ 3-3
Solution 3-1: Restricting and Sorting Data................................................................................................ 3-7
Practices for Lesson 4: Using Single-Row Functions to Customize Output ........................................... 4-1
Practices for Lesson 4: Overview............................................................................................................. 4-2
Practice 4-1: Using Single-Row Functions to Customize Output................................................................ 4-3
Solution 4-1: Using Single-Row Functions to Customize Output................................................................ 4-9

e

us

ฺC

y
onl

Practices for Lesson 5: Using Conversion Functions and Conditional Expressions ............................. 5-1
Practices for Lesson 5: Overview............................................................................................................. 5-2
Practice 5-1: Using Conversion Functions and Conditional Expressions.................................................... 5-3
Solution 5-1: Using Conversion Functions and Conditional Expressions.................................................... 5-9

ฺA
S
ru

e

P
c
e
t
er

Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions................................... 6-1
Practices for Lesson 6: Overview............................................................................................................. 6-2
Practice 6-1: Reporting Aggregated Data by Using Group Functions......................................................... 6-3
Solution 6-1: Reporting Aggregated Data by Using Group Functions......................................................... 6-6

ib
C
d

n

a
sity

Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins ............................................ 7-1
Practices for Lesson 7: Overview............................................................................................................. 7-2
Practice 7-1: Displaying Data from Multiple Tables by Using Joins............................................................ 7-3
Solution 7-1: Displaying Data from Multiple Tables by Using Joins............................................................ 7-8

r

e
niv

U
e
l
ac

Or

Practices for Lesson 8: Using Subqueries to Solve Queries ................................................................... 8-1
Practices for Lesson 8: Overview............................................................................................................. 8-2
Practice 8-1: Using Subqueries to Solve Queries ..................................................................................... 8-3
Solution 8-1: Using Subqueries to Solve Queries ..................................................................................... 8-6
Practices for Lesson 9: Using the Set Operators ..................................................................................... 9-1
Practices for Lesson 9: Overview............................................................................................................. 9-2
Practice 9-1: Using Set Operators ........................................................................................................... 9-3
Solution 9-1: Using Set Operators ........................................................................................................... 9-5
Practices for Lesson 10: Manipulating Data............................................................................................. 10-1
Practices for Lesson 10: Overview ........................................................................................................... 10-2
Practice 10-1: Managing Tables by Using DML Statements ...................................................................... 10-3
Solution 10-1: Managing Tables by Using DML Statements ...................................................................... 10-7
Practices for Lesson 11: Using DDL Statements to Create and Manage Tables ..................................... 11-1
Practices for Lesson 11: Overview ........................................................................................................... 11-2
Practice 11-1: Introduction to Data Definition Language ........................................................................... 11-3
Solution 11-1: Introduction to Data Definition Language ........................................................................... 11-7
Additional Practices and Solutions .......................................................................................................... 12-1
Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Oracle Database 12c: SQL Workshop I Table of Contents
i

......................... 12-2 Practice 1-1: Additional Practice .................................... 12-23 ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014......................................................................Unauthorized reproduction or distribution prohibitedฺ Copyright 2012............................................................................................. 12-11 Case Study: Online Book Store ............. 12-3 Solution 1-1: Additional Practice ........................................................................................................... Oracle and/or its affiliatesฺ Practices for Lesson 1.......................................................................................... Oracle Database 12c: SQL Workshop I Table of Contents ii y onl ........................... Oracle and/or its affiliates........................ 12-18 Solution 1-2 ............................................. All rights reserved.................................................................................................................................................... 12-17 Practice 1-2 ...............................................................

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 1: Introduction Chapter 1 . All rights reserved.Page 1 y onl . Oracle and/or its affiliates. Oracle and/or its affiliatesฺ ฺ e s u1: Practices for Lesson ฺ C Introduction SฺAฺ ru e cP Chapter 1 te nd a ty er b i C i rs e v i n U e l c Ora Copyright © 2014.

there may be exercises that are prefaced with the phrases “If you have time” or “If you want an extra challenge. you can also use SQL*Plus that is available in this course. All rights reserved. Oracle and/or its affiliates. You also set some SQL Developer preferences.Page 2 y onl . For any query. Notes • • All written practices use Oracle SQL Developer as the development environment. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.” Work on these exercises only if you have completed all other exercises within the allocated time. and browse your HR tables. You can experiment with saving and running command files. you start SQL Developer. Although it is recommended that you use Oracle SQL Developer. Practices for Lesson 1: Introduction Chapter 1 .Practices for Lesson 1: Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Perform the practices slowly and precisely. create a new database connection. the sequence of rows retrieved from the database may differ from the screenshots shown. In some of the practices. and would like an additional challenge to your skills. ask your instructor. If you have any questions at any time. Oracle and/or its affiliatesฺ Practice Overview In this practice.

Test the new connection. In the Connections Navigator. View the data of the DEPARTMENTS table. Browse the structure of the EMPLOYEES table. Browsing the Tables in the Connections Navigator a. Copyright © 2014. view the objects that are available to you in the Tables node. 2. in the Connections Navigator.Page 3 . b. If the status is Success. To create a new database connection. connect to the database by using this new connection. save them in the preceding location. right-click Connections and select New Connection from the context menu. In this practice. Start Oracle SQL Developer by using the SQL Developer Desktop icon. Note the following location for the practice files: /home/oracle/labs/sql1/labs If you are asked to save any practice files. you perform the following: • Start Oracle SQL Developer and create a new connection to the ora1 account. The practices are intended to cover most of the topics that are presented in the corresponding lesson. c. The solutions (if you require them) can be found at the end of this practice. Oracle and/or its affiliatesฺ Practice 1-1: Introduction Overview This is the first of many practices in this course. Oracle and/or its affiliates. Create a New Oracle SQL Developer Database Connection a. Tasks 1.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. b. • Use Oracle SQL Developer to examine the data objects in the ora1 account. The ora1 account contains the HR schema tables. The New/Select Database Connection dialog box appears. Testing the Oracle SQL Developer Database Connection and Connecting to the Database a. 4. 3. Practices for Lesson 1: Introduction Chapter 1 . Create a database connection by using the following information: Connection Name: myconnection Username: ora1 Password: ora1 Hostname: localhost ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity Port: 1521 r SID: ORCL Ensure that you select the Save Password check box. Verify that the following tables are present: COUNTRIES DEPARTMENTS EMPLOYEES JOB_GRADES JOB_HISTORY JOBS LOCATIONS REGIONS e niv U e l ac Or b. All rights reserved.

Solution 1-1: Introduction Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. right-click Connections and select New Connection from the context menu. Practices for Lesson 1: Introduction Chapter 1 . ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or 2. Creating a New Oracle SQL Developer Database Connection a. Starting Oracle SQL Developer Using the SQL Developer Desktop Icon Double-click the Oracle SQL Developer desktop icon. Oracle and/or its affiliatesฺ 1. Oracle and/or its affiliates. The SQL Developer Interface appears. To create a new database connection.Page 4 . All rights reserved. in the Connections Navigator. Copyright © 2014.

All rights reserved. Hostname: localhost b i C d v. Password: ora1 rte e iv. Practices for Lesson 1: Introduction Chapter 1 . Username: ora1 Pe c iii. Create a database connection by using the following information: ฺC A ฺ i. ฺ e us ฺ b. Oracle and/or its affiliates. Port: 1521 n ya vi.Page 5 y onl . Connection Name: myconnection S u r ii. Oracle and/or its affiliatesฺ The New / Select Database Connection dialog box appears. SID: ORCL t i s eryou select the Save Password check box.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Ensureithat v n U e acl Or Copyright © 2014.

Oracle and/or its affiliates. a SQL Worksheet for that connection opens automatically. If the status is Success.Page 6 . All rights reserved. Copyright © 2014. Oracle and/or its affiliatesฺ 3. connect to the database by using this new connection. Practices for Lesson 1: Introduction Chapter 1 . Test the new connection. ฺ e us ฺ ฺC y onl ฺA S ru b. e P c e t er ib C d n a sity r e niv U e l ac Or When you create a connection.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Testing and Connecting Using the Oracle SQL Developer Database Connection a.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Verify that the following tables are present: COUNTRIES DEPARTMENTS EMPLOYEES JOB_GRADES JOB_HISTORY JOBS LOCATIONS REGIONS e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. view the objects that are available to you in the Tables node. In the Connections Navigator.Page 7 . All rights reserved. Practices for Lesson 1: Introduction Chapter 1 . Oracle and/or its affiliatesฺ ฺ e us ฺ ฺC ฺA S ru y onl 4. Oracle and/or its affiliates. Browsing the Tables in the Connections Navigator a.

Oracle and/or its affiliates. View the data of the DEPARTMENTS table. ฺ e us ฺ ฺC c. Browse the structure of the EMPLOYEES table. All rights reserved.Page 8 y onl . Practices for Lesson 1: Introduction Chapter 1 . Oracle and/or its affiliatesฺ b.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 .Page 1 . All rights reserved.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates. Oracle and/or its affiliatesฺ ฺ e y onl s u2: Practices for Lesson ฺ ฺC the A Retrieving Data Using ฺ S u r SQL SELECT e Statement nd a ty P c e t Chapter er 2 b i C i rs e v i n U e l c Ora Copyright © 2014.

Oracle and/or its affiliatesฺ This practice covers the following topics: • Selecting all data from different tables • Describing the structure of tables • Performing arithmetic calculations and specifying column names ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliates. Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 .Page 2 y onl .Practices for Lesson 2: Overview Practice Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved.

There are four coding errors in the following statement. All rights reserved. Oracle and/or its affiliatesฺ In this practice. • After you have executed the query. last_name Ci d n sal x 12 ANNUAL SALARY a y FROM employees. The following SELECT statement executes successfully: ฺ SELECT * FROM job_grades. Copyright © 2014. Your first task is to create some reports based on the data from the Human Resources tables. True/False 2.sql script. To save a script in SQL Developer. Oracle and/or its affiliates. sit r e Task 2 niv U le points before you begin with the practices: Note the following c a r • O Save all your practice files at the following location: /home/oracle/labs/sql1/labs • Enter your SQL statements in a SQL Worksheet. Task 1 Test your knowledge: 1. make sure that you do not enter your next query in the same worksheet. Open a new worksheet. and then from the File menu. The following SELECT statement executes successfully: SELECT last_name. For DML and DDL statements. use the Run Script icon or press F5. click the Execute Statement icon in the SQL Worksheet. The queries cover most of the SELECT clauses and operations that you learned in this lesson. • To run the query. rte Can you identify them? e b SELECT employee_id.Practice 2-1: Retrieving Data Using the SQL SELECT Statement Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Alternatively. Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 . make sure that you use Save As to save it with a different file name. e us ฺ ฺC y onl ฺA S ru True/False Pe c 3. salary AS Sal FROM employees. you write simple SELECT queries.Page 3 . you can press F9. job_id. When you modify an existing script. make sure that the required SQL Worksheet is active. You have been hired as a SQL programmer for Acme Corporation. select Save As to save your SQL statement as a lab_<lessonno>_<stepno>.

Oracle and/or its affiliatesฺ 4. a. Determine the structure of the EMPLOYEES table. All rights reserved. Your first task is to determine the structure of the DEPARTMENTS table and its contents. Oracle and/or its affiliates. e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. ฺ e 5.Page 4 y onl . us ฺ ฺC ฺA S ru Your task is to determine the structure of the EMPLOYEES table and its contents. Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 .

sql so that you can dispatch this file to the HR department.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Provide an alias STARTDATE for the HIRE_DATE column. hire date.sql file to ensure that it runs correctly. Test your query in the lab_02_5b. Save your SQL statement to a file named lab_02_5b.Page 5 y onl . Open a new worksheet. Oracle and/or its affiliatesฺ b. Oracle and/or its affiliates. Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 . All rights reserved. The HR department wants a query to display the last name. and employee ID for each employee. with the employee ID appearing first. make sure that you do not enter your next query in the same worksheet. job ID. Note: After you have executed the query. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 . All rights reserved. Employee.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Then run the query again. Oracle and/or its affiliates. Oracle and/or its affiliatesฺ 6. complete the following exercises: 7. The HR department wants a query to display all unique job IDs from the EMPLOYEES table.sql to a new SQL Worksheet. and Hire Date. ฺ Task 3 e us ฺ ฺC If you have time. Name the columns Emp #. respectively.Page 6 . ฺA S ru y onl The HR department wants more descriptive column headings for its report on employees. e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Copy the statement from lab_02_5b. Job.

complete the following exercise: 9. Oracle and/or its affiliates.Page 7 . All rights reserved. e P c e t er To familiarize yourself with the data in the EMPLOYEES table. … ฺ e us ฺ ฺC y onl ฺA S ru If you want an extra challenge. Oracle and/or its affiliatesฺ 8. ib C d n a sity r e niv U e l ac Or … Copyright © 2014.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Separate each column output by a comma. Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 . create a query to display all the data from that table. The HR department has requested a report of all employees and their job IDs. Display the last name concatenated with the job ID (separated by a comma and space) and name the column Employee and Title. Name the column THE_OUTPUT.

as shown in line 2. last_name u r sal x 12 ANNUAL SALARY Pe c FROM employees. se u ฺ There are four coding errors in the following statement. The following SELECT statement executes successfully: SELECT last_name. Copyright © 2014. The alias should read  The ANNUAL n SALARY U ANNUAL_SALARY or should be enclosed within double quotation marks. The column is called  The EMPLOYEES table does not contain C d SALARY. To view the data contained in the DEPARTMENTS table: SELECT * FROM departments. a. n a y  The multiplication operator sit is *.Page 8 . Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 . ฺ y onl True/False 3. The following SELECT statement executes successfully: SELECT * FROM job_grades. Your first task is to create some reports based on the data from the Human Resources tables. le c a  O Arcomma is missing after the LAST_NAME column. Your first task is to determine the structure of the DEPARTMENTS table and its contents. True/False 2. Can you identify ฺC them? A ฺ S SELECT employee_id. Task 2 You have been hired as a SQL programmer for Acme Corporation. Oracle and/or its affiliates. Oracle and/or its affiliatesฺ 1. r e iv alias cannot include spaces. 4. rte e b i a column called sal. job_id. To determine the DEPARTMENTS table structure: DESCRIBE departments b. not x. salary AS Sal FROM employees.Solution 2-1: Retrieving Data Using the SQL SELECT Statement Task 1 Test your knowledge: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved.

hire_date StartDate FROM employees. a. Oracle and/or its affiliatesฺ b. Provide an alias STARTDATE for the HIRE_DATE column. SELECT DISTINCT job_id FROM employees. Oracle and/or its affiliates. respectively.ahire_date "Hire Date" y t i FROM employees. t r e b SELECT employee_id "Emp #". erWorksheet. d n job_id "Job". Determine the structure of the EMPLOYEES table.Page 9 .sql so that you can dispatch this file to the HR department. us ฺ ฺC ฺA S The HR department wants more descriptive column headings u for its report on employees. Save your SQL statement to a file named lab_02_5b. Your task is to determine the structure of the EMPLOYEES table and its contents. hire date. ฺ y onl column Employee and Title.sql file to ensure that it runs correctly.sql to a new SQL Name the columns P c e Emp #. '||job_id "Employee and Title" FROM employees. The HR department wants a query to display all unique job IDs from the EMPLOYEES table. DESCRIBE employees Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. complete the following exercises: 7. job ID. and employee ID for each employee. Job. last_name. The HR department wants a query to display the last name. SELECT employee_id. rs e v ni U le The HRc department has requested a report of all employees and their job IDs. Test your query in the lab_02_5b. Ci last_name "Employee". Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 .5. Copyright © 2014. 6. SELECT last_name||'. Employee. e Task 3 8. Display the a r last name concatenated with the job ID (separated by a comma and space) and name the O If you have time. job_id. and Hire Date. All rights reserved. Then run the query again. with the employee ID appearing first. Copy the statement from lab_02_5b.

' || manager_id || '.' || department_id THE_OUTPUT FROM employees. All rights reserved.' || first_name || '.' || email || '. complete the following exercise: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.' || phone_number || '.'|| job_id || '.' || last_name || '.' || hire_date || '. To familiarize yourself with the data in the EMPLOYEES table.Page 10 y onl . SELECT employee_id || '. create a query to display all the data from that table. Practices for Lesson 2: Retrieving Data Using the SQL SELECT Statement Chapter 2 .' || commission_pct || '. Separate each column output by a comma.' || salary || '.If you want an extra challenge. Oracle and/or its affiliatesฺ 9. Name the column THE_OUTPUT.

Page 1 . Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Oracle and/or its affiliatesฺ ฺ e y onl s u3: Practices for Lesson ฺ ฺC A Restricting and Sorting Data ฺ S ru e cP Chapter 3 te nd a ty er b i C i rs e v i n U e l c Ora Copyright © 2014.

Oracle and/or its affiliatesฺ This practice covers the following topics: • Selecting data and changing the order of the rows that are displayed • Restricting rows by using the WHERE clause • Sorting rows by using the ORDER BY clause • Using substitution variables to add flexibility to your SQL SELECT statements ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Practices for Lesson 3: Overview Practices Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . All rights reserved.Page 2 y onl .

Run your query. ฺ e us ฺ ฺC 2.Page 3 .sql to display the last name and salary for any employee whose salary is not in the range $5. Create a report that displays the last name and department number for employee number 176.000.000 through $12. Oracle and/or its affiliatesฺ Overview In this practice. Or Copyright © 2014.sql.000. You make the SQL statements more reusable and generic by including the ampersand substitution. Save your SQL statement as a file named lab_03_01. Oracle and/or its affiliates.sql. the HR department needs a report that displays the last name and salary of employees who earn more than $12.Practice 3-1: Restricting and Sorting Data Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Run the query. Task The HR department needs your assistance in creating some queries. Because of budget issues. Save your SQL statement as lab_03_03. 1. you build more reports by using statements that use the WHERE clause and the ORDER BY clause. ib C d n a sity r 3. y onl ฺA S ru e P c e t er Open a new SQL Worksheet. e niv U e l ac The HR department needs to find high-salary and low-salary employees. Modify lab_03_01. All rights reserved. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 .

Copyright © 2014.sql again. use ฺ ฺC who earn Modify lab_03_03.000 and $12. tec r e ib C nd a ity s r ive n e U needs a report that displays the last name and hire date of all The HRc department l employees Ora who were hired in 2006.S Label the columns u r Employee and Monthly Salary. 7. job ID.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Create a report to display the last name and job title of all employees who do not have a manager.sql as e P lab_03_06. respectively. and hire date for employees with the last names of Matos and Taylor. and are in department 20 or 50. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . 5. Run the statement in lab_03_06.Page 4 . All rights reserved. Oracle and/or its affiliatesฺ 4. Order the query in ascending order by hire date. Display the last name and department ID of all employees in departments 20 or 50 in ascending alphabetical order by last_name. Save lab_03_03.000. Oracle and/or its affiliates.sql. 8. ฺ y onl 6. Create a report to display the last name.sql to display the last name and salary of employees A ฺ between $5.

The HR department wants to run reports based on a manager. Save this query to a file named lab_03_10.) If you enter 12000 when prompted. You can test the data with the following values: n a sity er v i n sorted by last_name: manager_id =U 103. salary. Sort the data in descending order of salary and commissions.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliatesฺ 9. sorted by salary: manager_id = 124. All rights reserved. Oracle and/or its affiliates. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . salary. last name. and commission of all employees who earn commissions. (You can use the query created in Task 1 and modify it. They would like a report that displays the last name and salary of employees who earn more than an amount that the user specifies after a prompt. 10. the report displays the following results: ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d 11. and department for that manager’s employees.Page 5 . Create a query that prompts the user for a manager ID. Use the column’s numeric position in the ORDER BY clause. The HR department wants the ability to sort the report on a selected column. e cl a r O manager_id = 201.sql. sorted by employee_id: Copyright © 2014. and generates the employee ID. Create a report to display the last name. Members of the HR department want to have more flexibility with the queries that you are writing.

Oracle and/or its affiliatesฺ 12. and salary for all employees whose jobs are either that of a sales representative or a stock clerk.Page 6 . Modify lab_03_06. and commission for all employees whose commission is 20%. complete the following exercises: e us ฺ ฺC y onl 14. Display the last names of all employees where the third letter of the name is “a.If you have time. Rerun the statement in lab_03_15.sql. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . ฺ If you want an extra challenge.sql again. salary.000. Display the last name. Display the last names of all employees who have both an “a” and an “e” in their last name.sql as lab_03_15. ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac 15. complete the following exercises: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates.500. Or Copyright © 2014. Save lab_03_06. job. $3.500. or $7.” 13. and whose salaries are not equal to $2.sql to display the last name. All rights reserved.

SELECT FROM WHERE 3. 50) last_name ASC. hire_date r e FROM employees iv n U WHERE IN ('Matos'. last_name.000. Modify lab_03_03. last_name. Ora Display the last name and department ID of all employees in departments 20 or 50 in ascending alphabetical order by last_name. department_id employees employee_id = 176. and are in department 20 or 50. ฺ e us ฺ ฺC SELECT FROM WHERE 4. Save your SQL statement as a file named lab_03_01. job ID. Open a new SQL Worksheet.sql as lab_03_06. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . Oracle and/or its affiliates.000 and $12. Order the query in ascending order by hire date. Oracle and/or its affiliatesฺ 1. y onl The HR department needs to find high-salary and low-salary employees.sql to list the last name and salary of employees who earn between $5. department_id employees department_id IN (20. 'Taylor') eBY last_name l c ORDER hire_date.Page 7 . SELECT FROM WHERE ORDER BY 6. the HR department needs a report that displays the last name and salary of employees earning more than $12. respectively.000. 50). SELECT FROM WHERE AND last_name "Employee". 5. Run your query. All rights reserved. salary employees salary NOT BETWEEN 5000 AND 12000. salary "Monthly Salary" employees salary BETWEEN 5000 AND 12000 department_id IN (20. Create a report that displays the last name and department number for employee number 176. Run the statement in lab_03_06.sql.sql to display the last name and salary for all employees whose salary is not in the range $5. salary employees salary > 12000. and hire date for employees with the last names of Matos and Taylor. n a y SELECT last_name. last_name.000 through $12. Save your SQL statement as lab_03_03. Save lab_03_03. Label the columns Employee and Monthly Salary. SELECT FROM WHERE 2.sql again. sit job_id. ฺA S ru last_name. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.sql. e P c e t er ib C d Create a report to display the last name. Because of budget issues.sql. Copyright © 2014. Modify lab_03_01.Solution 3-1: Restricting and Sorting Data The HR department needs your assistance in creating some queries.000.

Oracle and/or its affiliatesฺ SELECT FROM WHERE 8.Page 8 . Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . Create a report to display the last name. They would like a report that displays the last name and salary of employees who earn more than an amount that the user specifies after aeprompt. Click OK. Create a report to display the last name and job title of all employees who do not have a manager. e t er Enter 12000 when prompted: b i C d SELECT last_name. ru S (You can use the query created in Task 1 and modify it. 3 DESC. SELECT FROM WHERE 9. last_name. U Enter 12000 when e cl a r O Copyright © 2014. commission_pct employees commission_pct IS NOT NULL 2 DESC. WHERE salary v i n prompted for a value in a dialog box.sql. ฺ y onl use ฺ Members of the HR department want to have more flexibility with theฺC queries that you are A ฺ writing. hire_date employees hire_date >= '01-JAN-06' AND hire_date < '01-JAN-07'. and commission for all employees who earn commissions. last_name. All rights reserved. The HR department needs a report that displays the last name and hire date of all employees who were hired in 2006. job_id employees manager_id IS NULL.) Save this query toca P file named lab_03_10. Sort data in descending order of salary and commissions. salary. salary. SELECT FROM WHERE ORDER BY 10. Oracle and/or its affiliates. salary n ya FROM employees t i s er > &sal_amt.7. last_name. Use the column’s numeric position in the ORDER BY clause.

$3. e us ฺ ฺC ฺ y onl ฺA S ru 13. commission_pct employees commission_pct = .sql as lab_03_15. complete the following exercises: 12. job. salary employees job_id IN ('SA_REP'. SELECT FROM WHERE AND last_name employees last_name LIKE '%a%' last_name LIKE '%e%'. r OSELECT FROM WHERE AND last_name.500. Oracle and/or its affiliatesฺ manager _id = 103. Display the last name. and commission for all employees whose commission amount is 20%.000. 7000). Rerun the statement in lab_03_15. The HR department wants the ability to sort the report on a selected column.500. Save lab_03_06. salary. You can test the data with the following values: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. salary. and salary for all employees whose job is that of a sales representative or a stock clerk. All rights reserved. and department for that manager’s employees.sql to display the last name. sorted by last_name manager_id = 201.sql. Display the last names of all employees where the third letter of the name is “a. Oracle and/or its affiliates. Practices for Lesson 3: Restricting and Sorting Data Chapter 3 . sorted by salary manager_id = 124. salary "Monthly Salary". and whose salary is not equal to $2. sorted by employee_id SELECT employee_id. 'ST_CLERK') salary NOT IN (2500. complete the following exercises: U e l ac 14.20. or $7. Copyright © 2014. 15. salary. Display the last names of all employees who have both an “a” and an “e” in their last name. Create a query that prompts the user for a manager ID. last name. last_name. e P c e t er ib C d n a sity r e niv If you want an extra challenge.11.” SELECT FROM WHERE last_name employees last_name LIKE '__a%'. Modify lab_03_06. and generates the employee ID. job_id.Page 9 . department_id FROM employees WHERE manager_id = &mgr_num ORDER BY &order_col. SELECT FROM WHERE last_name "Employee". If you have the time. The HR department wants to run reports based on a manager. 3500.sql again.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

e

us

ฺC

ฺA
S
ru

e

P
c
e
t
er

ib
C
d

n

a
sity

r

e
niv

U
e
l
ac

Or

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3: Restricting and Sorting Data
Chapter 3 - Page 10

y
onl

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

e

y
onl

s Using
u4:
Practices for Lesson

ฺC to
A
Single-Row Functions

S
u
r
Customize
Output
e

nd
a
ty

P
c
e
t
Chapter
er 4
b
i
C

i

rs
e
v
i

n

U
e
l
c

Ora

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4: Using Single-Row Functions to Customize Output
Chapter 4 - Page 1

Practices for Lesson 4: Overview
Practice Overview

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

This practice covers the following topics:

Writing a query that displays the current date

Creating queries that require the use of numeric, character, and date functions

Performing calculations of years and months of service for an employee

e

us

ฺC

ฺA
S
ru

e

P
c
e
t
er

ib
C
d

n

a
sity

r

e
niv

U
e
l
ac

Or

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4: Using Single-Row Functions to Customize Output
Chapter 4 - Page 2

y
onl

the results are evaluated from the innermost function to the outermost function. Run your query in the lab_04_02. and salary increased by 15. 2. Write a query to display the system date. salary. Oracle and/or its affiliates.5% (expressed as a whole number) for each employee. Save your SQL statement in a file named lab_04_02. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Label the column Date. Label the column New Salary. the output will be the date for the operating system on which the database resides.Practice 4-1: Using Single-Row Functions to Customize Output Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. number.sql. The HR department needs a report to display the employee number. Remember that for nested functions. 3. Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . Tasks 1.sql file. and date data types.Page 3 y onl . last name. Note: If your database is remotely located in a different time zone. Oracle and/or its affiliatesฺ Overview This practice provides a variety of exercises using the different functions that are available for character.

Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 .Page 4 .” or “M.sql to add a column that subtracts the old salary from the new salary. Save the contents of the file as lab_04_04. Oracle and/or its affiliates.sql. Label the column Increase.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. U e l ac Perform the following tasks: Or a. All rights reserved. Write a query that displays the last name (with the first letter in uppercase and all the other letters in lowercase) and the length of the last name for all employees whose name starts with the letters “J. Run the revised query. Sort the results by the employees’ last names.” “A. Modify your query in lab_04_02. Copyright © 2014. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity r e niv 5.” Give each column an appropriate label. Oracle and/or its affiliatesฺ 4.

ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a y t If you have time.” c. Order your results by the number of months employed. Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . The HR department n U each employee. The entered letter must be capitalized before being processed by the SELECT query. Oracle and/or its affiliatesฺ b. The number of months must be rounded to the closest whole number.Page 5 . Oracle and/or its affiliates. For example. complete the exercises: sifollowing r e iv wants to find the duration of employment for each employee. the output should show all employees whose last name starts with the letter “H. display the last name and calculate the number of months between e the date l c today and on which the employee was hired. Rewrite the query so that the user is prompted to enter the letter that the last name starts with. Label the column as ra OMONTHS_WORKED. All rights reserved.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. For 6. if the user enters “H” (capitalized) when prompted for a letter. Copyright © 2014. Modify the query such that the case of the letter that is entered does not affect the output.

the values in the MONTHS_WORKED column will differ for you. All rights reserved.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliatesฺ Note: Because this query depends on the date when it was executed. Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 .Page 6 y onl . ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliates.

Create a query to display the last name and salary for all employees. left-padded with the $ symbol. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r 8.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliatesฺ 7. e niv U e l ac Or Copyright © 2014. All rights reserved. Format the salary to be 15 characters long. Label the column SALARY.Page 7 y onl . Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . Oracle and/or its affiliates.

Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . Oracle and/or its affiliates. Oracle and/or its affiliatesฺ Create a query that displays the employees’ last names.Page 8 . Show the records in descending order of the employee’s tenure. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or 9. Copyright © 2014. Sort the data in descending order of salary. and indicates the amounts of their salaries with asterisks. All rights reserved. Label the number of weeks column as TENURE.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Each asterisk signifies a thousand dollars. Truncate the number of weeks value to 0 decimal places. Create a query to display the last name and the number of weeks employed for all employees in department 90. Label the column EMPLOYEES_AND_THEIR_SALARIES. Note: The TENURE value will differ because it depends on the date on which you run the query.

The HR department needs a report to display the employee number. Write a query that displays the last name (with the first letter in uppercase and all the other letters in lowercase) and the length of the last name for all employees whose name starts with the letters “J. a SELECT employee_id. ฺ Run your query in the file lab_04_02.Page 9 . salary. last_name.salary "Increase" U e FROM cl employees. Label the column New Salary. employee_id. 0) "New Salary" employees. last name.” Give each column an appropriate label. last_name. employee_id.sql. s r ROUND(salary * 1. Label the column Date.Solution 4-1: Using Single-Row Functions to Customize Output 1.5% (expressed as a whole number) for each employee. All rights reserved.” or “M.155. Save your SQL statement in a file named lab_04_02. Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . LENGTH(last_name) "Length" FROM employees WHERE last_name LIKE 'J%' OR last_name LIKE 'M%' OR last_name LIKE 'A%' ORDER BY last_name.155. salary. SELECT FROM 2. sysdate "Date" dual. ive n ROUND(salary * 1.sql to add column that subtracts the old salary rteaSave e from the new salary.155. Run the revised d n query. salary. the contents of the file as b i C lab_04_04. SELECT 4. Write a query to display the system date. salary.sql. and salary increased by 15. Oracle and/or its affiliates. Copyright © 2014. Oracle and/or its affiliatesฺ Note: If your database is remotely located in a different time zone. e us ฺ ฺC y onl ฺA S ru Pe c Modify your query in the lab_04_02. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. SELECT FROM 3. FROM 5. ity last_name. Sort the results by the employees’ last names.155. SELECT INITCAP(last_name) "Name". 0) .” “A. 0) "New Salary" employees. ROUND(salary * 1. ROUND(salary * 1. 0) "New Salary". the output will be the date for the operating system on which the database resides. Label the column Increase. a r O Perform the following tasks: a.sql.

” Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.b. SELECT last_name. e P c e t er ib C Note: Because this query depends the date when it was executed. Create a query to display the last name and salary for all employees. v i n SYSDATE. if the user enters H (capitalized) when prompted for a letter. Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . The HR department wants to find the duration of employment for each employee. left-padded with the $ symbol. Oracle and/or its affiliates. y t i s er ROUND(MONTHS_BETWEEN( SELECT last_name.Page 10 . the values in the ndon a MONTHS_WORKED column will differ for you. Modify the query such that the case of the letter that is entered does not affect the output. For each employee. Rewrite the query so that the user is prompted to enter the letter that starts the last name. SELECT INITCAP(last_name) "Name". LPAD(salary. For example. Label the column MONTHS_WORKED. Copyright © 2014. The number of months must be rounded to the closest whole number. Oracle and/or its affiliatesฺ SELECT INITCAP(last_name) "Name". LENGTH(last_name) "Length" FROM employees WHERE last_name LIKE UPPER('&start_letter%' ) ORDER BY last_name. ฺ e us ฺ ฺC If you have time. '$') SALARY FROM employees. complete the following exercises: y onl ฺA S ru 6. All rights reserved. Label the column SALARY. display the last name and calculate the number of months between today and the date on which the employee was hired. the output should show all employees whose last names start with the letter “H. Format the salary to be 15 characters long. c. LENGTH(last_name) "Length" FROM employees WHERE last_name LIKE '&start_letter%' ORDER BY last_name. hire_date)) MONTHS_WORKED U e l FROM employees rac BY months_worked. OORDER 7. Order your results by the number of months employed. 15. The entered letter must be capitalized before being processed by the SELECT query.

All rights reserved. '*') EMPLOYEES_AND_THEIR_SALARIES FROM employees ORDER BY salary DESC. Truncate the number of weeks value to 0 decimal places. Label the column EMPLOYEES_AND_THEIR_SALARIES. SELECT last_name. e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliates. Label the number of weeks column as TENURE. Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . Create a query that displays employees’ last names. Note: The TENURE value will differ because it depends on the date when you run the query. Create a query to display the last name and the number of weeks employed for all employees in department 90. Oracle and/or its affiliatesฺ 8. SELECT last_name. 9. and indicates the amounts of their salaries with asterisks. trunc((SYSDATE-hire_date)/7) AS TENURE FROM employees WHERE department_id = 90 ORDER BY TENURE DESC. Sort the data in descending order of salary. Show the records in descending order of the employee’s tenure. salary/1000.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Each asterisk signifies a thousand dollars.Page 11 ฺ y onl . rpad(' '.

Practices for Lesson 4: Using Single-Row Functions to Customize Output Chapter 4 . Oracle and/or its affiliatesฺ ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliates. All rights reserved.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 12 y onl .

Oracle and/or its affiliatesฺ ฺ e y onl s Using u5: Practices for Lesson ฺ ฺC A Conversion Functions and ฺ S Conditional eru Expressions nd a ty P c e t Chapter er 5 b i C i rs e v i n U e l c Ora Copyright © 2014.Page 1 . Oracle and/or its affiliates. Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 . All rights reserved.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.

• Creating queries that use conditional expressions such as CASE . Oracle and/or its affiliatesฺ This practice covers the following topics: • Creating queries that use the TO_CHAR and TO_DATE functions. SEARCHED CASE. and DECODE ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Page 2 y onl . All rights reserved. Oracle and/or its affiliates.Practices for Lesson 5: Overview Practice Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 .

Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 .Practice 5-1: Using Conversion Functions and Conditional Expressions Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 3 y onl . and DECODE.>. and conditional expressions such as CASE. Oracle and/or its affiliates. Oracle and/or its affiliatesฺ Overview This practice provides a variety of exercises using the TO_CHAR and TO_DATE functions. Label the column Dream Salaries. Create a report that produces the following for each employee: <employee last name> earns <salary> monthly but wants <3 times salary. searched CASE. Tasks 1. All rights reserved. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

” ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Display each employee’s last name. Format the dates to appear in a format that is similar to “Monday.Page 4 y onl . Oracle and/or its affiliates. All rights reserved. Oracle and/or its affiliatesฺ 2. 2000. and salary review date. Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 . which is the first Monday after six months of service. the Thirty-First of July. Label the column REVIEW. hire date.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.” Label the column COMM. If an employee does not earn commission. show “No Commission. Create a query that displays employees’ last names and commission amounts. Oracle and/or its affiliatesฺ 3. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Page 5 y onl . Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 . All rights reserved. Oracle and/or its affiliates.

Oracle and/or its affiliates. Oracle and/or its affiliatesฺ Job Grade AD_PRES ST_MAN IT_PROG SA_REP ST_CLERK None of the above A B C D E 0 ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.4. Using the CASE function. write a query that displays the grade of all employees based on the value of the JOB_ID column. using the following data: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 6 y onl . Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 . All rights reserved.

Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 7 y onl . Oracle and/or its affiliatesฺ 5. All rights reserved. Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 . Rewrite the statement in the preceding exercise by using the searched CASE syntax. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

Rewrite the statement in the preceding exercise by using the searched DECODE syntax. All rights reserved.Page 8 y onl . Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 . Oracle and/or its affiliatesฺ 6.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

and salary review date.00') || ' monthly but wants ' || TO_CHAR(salary * 3. hire_date. SELECT FROM 2. Label the column REVIEW. Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 .Page 9 . Pe c NVL(TO_CHAR(commission_pct). hire date.999. which is the first Monday after six months of service. 'fm$99. 2000. last_name || ' earns ' || TO_CHAR(salary. TO_CHAR(NEXT_DAY(ADD_MONTHS(hire_date. 'fm$99.” SELECT last_name. show “No Commission. b i C d Using the CASE function. Label the column Dream Salaries. rte 'No Commission') COMM e FROM employees. ฺ y onl 3. If an A ฺ employee does not earn commission.'MONDAY'). Oracle and/or its affiliatesฺ 1.” Label the column COMM.Solution 5-1: Using Conversion Functions and Conditional Expressions Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. 'fmDay. S u r SELECT last_name.999. Format the dates to appear in a format that is similar to “Monday. Create a report that produces the following for each employee: <employee last name> earns <salary> monthly but wants <3 times salary. 6). use ฺ C Create a query that displays employees’ last names and commissionฺamounts. Display each employee’s last name. the Thirty-First of July.>. Oracle and/or its affiliates. All rights reserved. YYYY') REVIEW FROM employees. 4. using the following data: y it s r Job Grade ive n U AD_PRES e A l c ST_MAN B ra O IT_PROG C SA_REP ST_CLERK None of the above D E 0 Copyright © 2014. write a query n that displays the grade of all employees based on the a value of the JOB_ID column.' "Dream Salaries" employees. "the" Ddspth "of" Month.00') || '.

Page 10 . Rewrite the statement in the preceding exercise by using the searched DECODE syntax. 'D'. n U e l 'ST_MAN'. nd a 'ST_CLERK'. 'B'. Oracle and/or its affiliatesฺ SELECT job_id. All rights reserved. ity'SA_REP'. decode (job_id. Copyright © 2014. c a r 'AD_PRES'.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 5: Using Conversion Functions and Conditional Expressions Chapter 5 . O 'E'. s r ive 'IT_PROG'. SELECT job_id. Rewrite the statement in the preceding exercise by using the searched CASE syntax. ib C SELECT job_id. '0')GRADE FROM employees. 'A'. 'C'. job_id 'ST_CLERK' THEN 'SA_REP' THEN 'IT_PROG' THEN 'ST_MAN' THEN 'AD_PRES' THEN '0' END GRADE 'E' 'D' 'C' 'B' 'A' 5. job_id = job_id = job_id = job_id = job_id = '0' END 'ST_CLERK' 'SA_REP' 'IT_PROG' 'ST_MAN' 'AD_PRES' GRADE THEN THEN THEN THEN THEN ฺ e us ฺ ฺC ฺA S ru e P c e t er 'E' 'D' 'C' 'B' 'A' y onl 6. CASE WHEN WHEN WHEN WHEN WHEN ELSE FROM employees. Oracle and/or its affiliates. CASE WHEN WHEN WHEN WHEN WHEN ELSE FROM employees.

Page 1 .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Oracle and/or its affiliatesฺ ฺ e y onl s u6: Practices for Lesson ฺ ฺC Data A Reporting Aggregated ฺ u S Functions Using theerGroup nd a ty P c e t Chapter er 6 b i C i rs e v i n U e l c Ora Copyright © 2014. Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 . Oracle and/or its affiliates.

Page 2 y onl . All rights reserved.Practices for Lesson 6: Overview Practice Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliatesฺ This practice covers the following topics: • Writing queries that use group functions • Grouping by rows to achieve multiple results • Restricting groups by using the HAVING clause ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliates. Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 .

sql. Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 . Tasks Determine the validity of the following statements. The WHERE clause restricts rows before inclusion in a group calculation. Run the query. Round your results to the nearest whole number. lowest. 1. Save your SQL statement as lab_06_04. Group functions include nulls in calculations.sql display the minimum. v i n U e cl a r O Copyright © 2014. Sum. True/False 3. respectively.sql. Group functions work across many rows to produce one result per group. True/False ฺ The HR department needs the following reports: 4. All rights reserved. ฺA S ru e P c e t er ib C 5. True/False 2. Oracle and/or its affiliates. sum.sql again. you should be familiar with using the group functions and selecting groups of data. as lab_06_05. maximum. and average salary of all employees. Modify the query in lab_06_04.sql a average salary for each job type. e us ฺ ฺC y onl Find the highest. and Average. and ndSavetolab_06_04. Oracle and/or its affiliatesฺ After completing this practice. Circle either True or False.Page 3 .Practice 6-1: Reporting Aggregated Data by Using Group Functions Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. y t i s Run the statement in er lab_06_05. sum. Minimum. Label the columns Maximum.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 4 .000 or less. Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 . Save the script to a file named lab_06_06. Sort the output in descending order of salary. Write a query to display the number of people with the same job. All rights reserved. Create a report to display the manager number and the salary of the lowest-paid employee for that manager. Generalize the query so that the user in the HR department is prompted for a job title. Or If you have time. Oracle and/or its affiliatesฺ 6. ฺ e us ฺ ฺC 7. e niv U e l ac Find the difference between the highest and lowest salaries. complete the following exercises: 9. y onl ฺA S ru e P c e t er Determine the number of managers without listing them. Exclude any groups where the minimum salary is $6. n a sity r 8. Copyright © 2014. Run the query. Label the column Number of Managers. Enter IT_PROG when prompted.sql. Oracle and/or its affiliates. Exclude anyone whose manager is not known. ib C d Hint: Use the MANAGER_ID column to determine the number of managers. Label the column DIFFERENCE.

Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 . 11. Create appropriate column headings. complete the following exercises: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. giving each column an appropriate heading.If you want an extra challenge. Oracle and/or its affiliates. Oracle and/or its affiliatesฺ 10. the salary for that job based on the department number. and 90. Create a matrix query to display the job. and 2008.Page 5 y onl . for departments 20. and the total salary for that job. 80. Create a query to display the total number of employees and. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. the number of employees hired in 2005. 2007. All rights reserved. of that total. 50. 2006.

Copyright © 2014. True/False The HR department needs the following reports: 4. maximum. The WHERE clause restricts rows before inclusion in a group calculation.0) "Maximum".sql. Run the query.sql as lab_06_05. Sum. Save your SQL statement as lab_06_04. Run the query. 6. and Average.0) ROUND(AVG(salary). Minimum. Oracle and/or its affiliates. "Maximum".sql. Label the columns Maximum. "Minimum". Circle either True or False. respectively. ฺ SELECT ROUND(MAX(salary).sql to display the minimum.Solution 6-1: Reporting Aggregated Data by Using Group Functions Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.0) e l c a ROUND(SUM(salary). "Minimum".0) FROM employees. n a sity er v i n SELECT job_id. "Sum". 1. Group functions work across many rows to produce one result per group. True/False 3. ROUND(MAX(salary). Round your results to the nearest whole number. Run the statement in lab_06_05.sql. "Average" FROM employees GROUP BY job_id. Save lab_06_04.0) ROUND(MIN(salary). Oracle and/or its affiliatesฺ Determine the validity of the following statements. SELECT job_id. "Average" e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d Modify the query in lab_06_04. Generalize the query so that the user in the HR department is prompted for a job title. and average salary of all employees. lowest. "Sum". Save the script to a file named lab_06_06. Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 . sum. Find the highest.sql again.Page 6 . Group functions include nulls in calculations.0) U ROUND(MIN(salary).0) ROUND(SUM(salary). sum. and average salary for each job type. All rights reserved.0) Or ROUND(AVG(salary). 5. Enter IT_PROG when prompted and click OK. Write a query to display the number of people with the same job. True/False 2. COUNT(*) FROM employees GROUP BY job_id.

SUM(DECODE(TO_CHAR(hire_date.1. 'YYYY'). e P c e t r SELECT manager_id. Find the difference between the highest and lowest salaries. ฺ e us ฺ ฺC If you have time. 2007. Exclude anyone whose manager is not known.Page 7 .MIN(salary) DIFFERENCE employees. 'YYYY').0))"2006". the number of employees hired in 2005. 2006. 'YYYY'). complete the following exercises: 10. Sort the output in descending order of salary. All rights reserved. SUM(DECODE(TO_CHAR(hire_date.000 or less. and 2008. SUM(DECODE(TO_CHAR(hire_date.1. MIN(salary) e b i FROM employees C d WHERE manager_id IS NOT NULL n GROUP BY manager_id ya t i s HAVING MIN(salary) > 6000 er v i ORDER BY n MIN(salary) DESC. Label the column DIFFERENCE. Label the column Number of Managers. Oracle and/or its affiliates. Create appropriate column headings. SUM(DECODE(TO_CHAR(hire_date. U e cl a r O If you want an extra challenge. of that total. Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 .0))"2007".2006. 7. complete the following exercises: 9.2007. Exclude any groups where the minimum salary is $6. SELECT FROM MAX(salary) . 'YYYY'). Oracle and/or its affiliatesฺ SELECT job_id. COUNT(*) FROM employees WHERE job_id = '&job_title' GROUP BY job_id.1.0))"2008" Copyright © 2014. 8. Create a query that displays the total number of employees and. SELECT FROM COUNT(*) total. employees.2008. Determine the number of managers without listing them. Hint: Use the MANAGER_ID column to determine the number of managers. y onl ฺA S ru Create a report to display the manager number and the salary of the lowest-paid employee for that manager.1. SELECT COUNT(DISTINCT manager_id) "Number of Managers" FROM employees.0))"2005".Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.2005.

and the total salary for that job. 50".Page 8 y onl . . and 90. salary)) salary)) salary)) salary)) "Dept "Dept "Dept "Dept 20". 50. 20. Oracle and/or its affiliates. 90. 80". Practices for Lesson 6: Reporting Aggregated Data Using the Group Functions Chapter 6 . . SUM(DECODE(department_id SUM(DECODE(department_id SUM(DECODE(department_id SUM(DECODE(department_id SUM(salary) "Total" FROM employees GROUP BY job_id. Oracle and/or its affiliatesฺ SELECT job_id "Job". 80. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. . 90". giving each column an appropriate heading. 80. . Create a matrix query to display the job. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. 50.11. the salary for that job based on the department number. for departments 20.

Oracle and/or its affiliatesฺ ฺ e y onl s u7: Practices for Lesson ฺ ฺC Multiple A Displaying Data from ฺ S u r Tables Using e Joins nd a ty P c e t Chapter er 7 b i C i rs e v i n U e l c Ora Copyright © 2014. Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 .Page 1 . All rights reserved.

Oracle and/or its affiliatesฺ This practice covers the following topics: • Joining tables using an equijoin • Performing outer and self-joins • Adding conditions ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 . Oracle and/or its affiliates. All rights reserved.Practices for Lesson 7: Overview Practice Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 2 y onl .

and department name for these employees. Show the location ID. Write a query for the HR department to produce the addresses of all the departments. 2. Use a NATURAL JOIN to produce the results. All rights reserved. e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. ฺ y onl The HR department needs a report of all employees with corresponding departments. and country in the output. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 . department number. city. Write a query to display the last name. street address. Use the LOCATIONS and COUNTRIES tables.Page 3 . Oracle and/or its affiliates.Practice 7-1: Displaying Data from Multiple Tables by Using Joins Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliatesฺ This practice is intended to give you experience in extracting data from multiple tables using the SQL:1999–compliant joins. state or province. Tasks 1.

Page 4 . Save your SQL statement as lab_07_05. respectively. including King. Modify lab_07_04. Oracle and/or its affiliatesฺ 3. Label the columns Employee. who has no manager. Oracle and/or its affiliates. All rights reserved.sql. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or 5. Emp#. Run the query in lab_07_05. Display the last name. … Copyright © 2014.sql. and the department name for all employees who work in Toronto. Save your SQL statement as lab_07_04. and Mgr#. Create a report to display employees’ last names and employee numbers along with their managers’ last names and manager numbers. Order the results by employee number. Run the query. The HR department needs a report of employees in Toronto. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 . 4.sql.sql to display all employees. Manager.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. job. department number.

U e l ac Or Copyright © 2014. and all the employees who work in the same department as a given employee. job.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates. All rights reserved. and grade for all employees. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 . Save the script to a file named lab_07_06. a sity r e niv The HR department needs a report on job grades and salaries. To familiarize yourself with the JOB_GRADES table. ฺ e us ฺ ฺC … y onl ฺA S ru e P c e t er ib C d n 7. Then create a query that displays the name. first show the structure of the JOB_GRADES table. department numbers.sql. department name. Create a report for the HR department that displays employee last names. Oracle and/or its affiliatesฺ 6. Give each column an appropriate label.Page 5 . salary.

Create a query to display the name Ci and hire date of any employee hired after d n employee Davies. y onl Copyright © 2014. Oracle and/or its affiliates. Oracle and/or its affiliatesฺ ฺ e us ฺ ฺC ฺA S ru Pe c rte of all employees who were hired after The HR department wants to determine the names e b Davies. a y sit r e niv U le c a Or If you want an extra challenge.Page 6 .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 . complete the following exercises: 8. All rights reserved.

Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 . The HR department needs to find the names and hire dates of all employees who were hired before their managers. along with their managers’ names and hire dates. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Save the script to a file named lab_07_09.sql.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved.Page 7 y onl . Oracle and/or its affiliatesฺ 9. Oracle and/or its affiliates.

last_name "Manager". Show the location ID. Copyright © 2014.acl r OSELECT w. s ฺ C ฺ SELECT e.department_id = d. e. w. city. Label the columns Employee. and department name for all employees who work in u Toronto. Order the results by employee number. and country in the output. e. v ni Manager. state_province. m. Emp#. SELECT location_id. 4. e o job. Save your SQL statement as lab_07_04.sql. Oracle and/or its affiliatesฺ 1. department_id.sql to display all employees.sql.city) a =n'toronto'.Solution 7-1: Displaying Data from Multiple Tables by Using Joins Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. who has no manager.last_name "Employee". The HR department needs a report of all employees with corresponding departments. m.employee_id "EMP#". Run the e query. department number.manager_id = m.manager_id = m. Use a NATURAL JOIN to produce the results. andUMgr#. country_name FROM locations NATURAL JOIN countries. Oracle and/or its affiliates. d.department_id) P tec JOIN locations l r e ib USING (location_id) C d WHERE LOWER(l.sql. "Mgr#" Modify lab_07_04. All rights reserved.job_id. Run the query in lab_07_05. Write a query to display the last name. ity Create a report to display employees’ last names and employee numbers along with their s r e managers’ last names and manager numbers. SELECT w. including King. respectively. street_address. ฺ y l n The HR department needs a report of employees in Toronto.employee_id) ORDER BY 2.department_id. SELECT last_name.last_name "Manager". Write a query for the HR department to produce the addresses of all the departments. department_name FROM employees JOIN departments USING (department_id). 2.last_name.employee_id "Mgr#" FROM employees w LEFT OUTER JOIN employees m ON (w.Page 8 .employee_id "EMP#". department number.employee_id). 3. Display the last name. state or province.department_name ฺA S FROM employees e JOIN departments d eru ON (e.employee_id employees w JOIN employees m (w. Use the LOCATIONS and COUNTRIES tables. FROM ON 5. m. street address. and department name for all the employees. w. Save your SQL statement as lab_07_05. city. m.last_name "Employee". Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 .

c. DESC JOB_GRADES / SELECT e.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.manager_id = m. along with their managers’ names and hire dates. department name. The HR department needs a report on job grades and salaries. e. The HR department needs to find the names and hire dates of all employees who were hired before their managers. and grade for all employees.last_name. e us ฺ ฺC ฺ y onl ฺA S ru Pe c rteexercises: If you want an extra challenge.hire_date < e. The HR department wants to determine d nthe name and hire date of any employee hired after Davies.grade_level FROM employees e JOIN departments d ON (e.lowest_sal AND j. m. To familiarize yourself with the JOB_GRADES table. w.department_name.department_id = d.hire_date niv U FROMle employees e JOIN employees davies rac (davies.employee_id ORDER BY e. Give each column an appropriate label. Create a query to display a y employee Davies. davies. e.last_name. e. first show the structure of the JOB_GRADES table.sql. sit r e SELECT e.department_id) JOIN job_grades j ON (e.employee_id) WHERE w. e. SELECT e.department_id department. Run the query.last_name = 'Davies') OON WHERE 9. Create a report for the HR department that displays employee last names.Page 9 . c. Oracle and/or its affiliates. Then create a query that displays the name. j. 7.salary.salary BETWEEN j.last_name.last_name. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 .highest_sal).job_id. m.employee_id <> c. Save the script to a file named lab_07_09. d.hire_date < m. Save the script to a file named lab_07_06.sql.department_id) WHERE e.department_id = c.last_name. Copyright © 2014.hire_date FROM employees w JOIN employees m ON (w.hire_date. All rights reserved. job.department_id.last_name.hire_date. e.hire_date. salary. and all employees who work in the same department as a given employee.last_name employee. department numbers. complete the following e b i names of all employees who were hired after Cthe 8. SELECT w.last_name colleague FROM employees e JOIN employees c ON (e. Oracle and/or its affiliatesฺ 6.

Oracle and/or its affiliates. Practices for Lesson 7: Displaying Data from Multiple Tables Using Joins Chapter 7 .Page 10 y onl .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Oracle and/or its affiliatesฺ ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

Page 1 . Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliatesฺ ฺ e y onl s Using u8: Practices for Lesson ฺ ฺC Queries A Subqueries to Solve ฺ S ru e cP Chapter 8 te nd a ty er b i C i rs e v i n U e l c Ora Copyright © 2014. All rights reserved. Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 .

Page 2 y onl .Practices for Lesson 8: Overview Practice Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 . Oracle and/or its affiliates. Oracle and/or its affiliatesฺ This practice covers the following topics: • Creating subqueries to query values based on unknown criteria • Using subqueries to find values that exist in one set of data and not in another ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

Make sure that it runs and produces the data that you anticipate before you code the outer query.Page 3 . All rights reserved. if the user enters Zlotkey. Tasks 1. The query then displays the last name and hire date of any employee in the same department as the employee whose name the user supplies (excluding that employee). Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 . r e niv U e l ac Or Copyright © 2014. The HR department needs a query that prompts the user for an employee’s last name. Oracle and/or its affiliates. you may want to create the inner query first. For example. and salary of all employees who earn more than the average salary. Sort the results in ascending order by salary. find all employees who work with Zlotkey (excluding Zlotkey). last name. For practice questions. Oracle and/or its affiliatesฺ In this practice. ib C d n a sity Create a report that displays the employee number. you write complex queries using nested SELECT statements.Practice 8-1: Using Subqueries to Solve Queries Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er 2.

Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 . Oracle and/or its affiliates. 4.Page 4 . Run your query. Save this to a file named Modify the query so thatrs the e lab_08_04. The HR department needs a report that displays the last name. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d 5. n a y it user is prompted for a location ID.” Save your SQL statement as lab_08_03. department number. and job ID of all employees whose department location ID is 1700.sql.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Copyright © 2014. Write a query that displays the employee number and last name of all employees who work in a department with any employee whose last name contains the letter “u.sql. niv U le c a Create Or a report for HR that displays the last name and salary of every employee who reports to King. All rights reserved. Oracle and/or its affiliatesฺ 3.

sql to display the employee number. Copyright © 2014. Create a report for HR that displays the department number. All rights reserved. last name. and who work in a department with any employee whose last name contains the letter “u. complete U e cl query in lab_08_03.” Save lab_08_03. Run the statement in lab_08_08. Oracle and/or its affiliates.Page 5 . Oracle and/or its affiliatesฺ 6. Create a report that displays a list of all employees whose salary is more than the salary of any employee from department 60. last name.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 . 7. and job ID for every employee in the Executive department.sql again. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity er v i n the following exercise: If you have time. Modify the a r O salary of all employees who earn more than the average salary.sql as lab_08_08. and 8.sql.

e us ฺ ฺC ฺ y onl ฺA S ru Note: UNDEFINE and SELECT are individual queries. Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 .Page 6 . find all employees who work with Zlotkey (excluding Zlotkey). hire_date FROM employees WHERE department_id = (SELECT department_id FROM employees WHERE last_name = '&&Enter_name') AND last_name <> '&Enter_name'.Solution 8-1: Using Subqueries to Solve Queries Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. For example.Execute the below SELECT statements to retrieve the values from employees table SELECT last_name. salary nd a FROM employeesity r>s(SELECT AVG(salary) WHERE salary e v ni FROM employees) U e l c BY salary. if the user enters Zlotkey.sql. Write a query that displays the employee number and last name of all employees who work in a department with any employee whose last name contains the letter “u. --Execute the UNDEFINE command to remove a variable UNDEFINE Enter_name -. The query then displays the last name and hire date of any employee in the same department as the employee whose name the user supplies (excluding that employee). last_name FROM employees WHERE department_id IN (SELECT department_id FROM employees WHERE last_name like '%u%'). The HR department needs a query that prompts the user for an employee’s last name. and salary of all employees who earn more than the average salary. Sort the results in ascending order by salary. Oracle and/or its affiliatesฺ 1.” Save your SQL statement as lab_08_03. e 2. ib C SELECT employee_id. P c e t er Create a report that displays the employee number. last_name. ORDER Ora 3. execute them one after the other or press Ctrl + A + F9 to run them together. Copyright © 2014. Oracle and/or its affiliates. SELECT employee_id. last name. Run your query.

department_id. Create a report that displays a list of all employees whose salary is more than the salary of any employee from department 60. 7. Copyright © 2014. department_id. ฺ e us ฺ ฺC y onl ฺA S ru Create a report for HR that displays the last name and salary of every employee who reports to King. The HR department needs a report that displays the last name. e P c e t er SELECT last_name. job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE department_name = 'Executive'). last_name.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. last name.sql. 5. SELECT department_id. and job ID of all employees whose department location ID is 1700. job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = &Enter_location). SELECT last_name FROM employees WHERE salary > ANY (SELECT salary FROM employees WHERE department_id=60). SELECT last_name. Oracle and/or its affiliatesฺ 4. job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = 1700). Modify the query so that the user is prompted for a location ID. department number. and job ID for every employee Or in the Executive department. SELECT last_name.Page 7 . Oracle and/or its affiliates. Save this to a file named lab_08_04. salary FROM employees WHERE manager_id = (SELECT employee_id FROM employees WHERE last_name = 'King'). Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 . ib C d n a sity r e niv 6. U e l Createaacreport for HR that displays the department number.

Oracle and/or its affiliates.sql to lab_08_08. All rights reserved.” Save lab_08_03. Run the statement in lab_08_08. last_name.sql. Practices for Lesson 8: Using Subqueries to Solve Queries Chapter 8 . SELECT employee_id. Modify the query in lab_08_03.sql to display the employee number.Page 8 y onl . salary FROM employees WHERE department_id IN (SELECT department_id FROM employees WHERE last_name like '%u%') AND salary > (SELECT AVG(salary) FROM employees).If you have time. Oracle and/or its affiliatesฺ 8.sql again. last name. complete the following exercise: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. and salary of all employees who earn more than the average salary and who work in a department with any employee whose last name contains the letter “u. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.

All rights reserved.Page 1 . Oracle and/or its affiliates. Practices for Lesson 9: Using the Set Operators Chapter 9 . Oracle and/or its affiliatesฺ ฺ e y onl s Using u9: Practices for Lesson ฺ ฺC A the Set Operators ฺ S ru e cP Chapter 9 te nd a ty er b i C i rs e v i n U e l c Ora Copyright © 2014.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.

Practices for Lesson 9: Using the Set Operators Chapter 9 . you create reports by using the following: • UNION operator • INTERSECT operator • MINUS operator ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliatesฺ In this practice. Oracle and/or its affiliates.Practices for Lesson 9: Overview Practice Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved.Page 2 y onl .

Oracle and/or its affiliates. ฺC A ฺ S u r Pe c e rtdepartments Produce a list of all the employees who workein 50 and 80. The HR department needs a list of department IDs for departments that do not contain the job ID ST_CLERK. job ID. Use the set operators to create this report. and department ID by C nd a ity s r ive n U e l c Ora Create a report that lists the detail of all employees who are sales representatives and are currently working in the sales department. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Display the b i using the set operators. employee ID. Copyright © 2014. Oracle and/or its affiliatesฺ Tasks 1. Practices for Lesson 9: Using the Set Operators Chapter 9 . 4. Use the set operators to create this u ฺ report.Practice 9-1: Using Set Operators Overview In this practice. you write queries using the set operators UNION. and MINUS. 3. yฺ l n The HR department needs a list of countries that have no departments located ino them. INTERSECT. e s Display the country IDs and the names of the countries.Page 3 . 2.

Oracle and/or its affiliatesฺ 5. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Page 4 y onl .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Practices for Lesson 9: Using the Set Operators Chapter 9 . The HR department needs a report with the following specifications: • Last names and department IDs of all employees from the EMPLOYEES table. All rights reserved. regardless of whether or not they belong to a department • Department IDs and department names of all departments from the DEPARTMENTS table. Oracle and/or its affiliates. regardless of whether or not they have employees working in them Write a compound query to accomplish this report.

The HR department needs a list of department IDs for departments that do not contain the job ID ST_CLERK. department_id departments department_id employees job_id = 'ST_CLERK'. The HR department needs a list of countries that have no departments located in them. SELECT FROM MINUS SELECT FROM WHERE 2.country_name FROM locations l JOIN countries c ON (l. Oracle and/or its affiliatesฺ 1. job ID. department_id OSELECT FROM EMPLOYEES WHERE department_id=80. Display the b i employee ID. ฺ e us ฺ ฺC y onl ฺA S ru Pe c e rtdepartments Produce a list of all the employees who workein 50 and 80.c. job_id.country_name FROM countries MINUS SELECT l. a job_id. Create a report that lists the detail of all employees who are sales representatives and are currently working in the sales department.Solution 9-1: Using Set Operators Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Copyright © 2014.country_id = c. All rights reserved.location_id=l. Use the set operators to create this report. department_id y t i FROM EMPLOYEESrs ive WHERE department_id=50 n U UNION ALL e l rac employee_id. SELECT country_id.location_id. 4. Oracle and/or its affiliates. Practices for Lesson 9: Using the Set Operators Chapter 9 . 3.Page 5 . Display the country IDs and the names of the countries. and department ID by using the set operators.country_id) JOIN departments d ON d.country_id. C d n SELECT employee_id. SELECT EMPLOYEE_ID FROM EMPLOYEES WHERE JOB_ID='SA_REP' INTERSECT SELECT EMPLOYEE_ID FROM EMPLOYEES WHERE DEPARTMENT_ID=80. Use the set operators to create this report.

Page 6 y onl .department_name FROM departments.department_id.5.TO_CHAR(null)dept_name FROM employees UNION SELECT TO_CHAR(null). Oracle and/or its affiliatesฺ • Last names and department IDs of all employees from the EMPLOYEES table.department_id. The HR department needs a report with the following specifications: • Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. regardless of whether or not they have employees working in them Write a compound query to accomplish this report. regardless of whether or not they belong to a department Department IDs and department names of all departments from the DEPARTMENTS table. SELECT last_name. Practices for Lesson 9: Using the Set Operators Chapter 9 . All rights reserved. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliates.

All rights reserved.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates. Oracle and/or its affiliatesฺ ฺ e s u10: Practices for Lesson ฺ C ManipulatingSData ฺAฺ ru e cP Chapter 10 te nd a ty er b i C i rs e v i n U e l c Ora Copyright © 2014. Practices for Lesson 10: Manipulating Data Chapter 10 .Page 1 y onl .

Oracle and/or its affiliates.Page 2 y onl . Oracle and/or its affiliatesฺ This practice covers the following topics: • Inserting rows into tables • Updating and deleting rows in a table • Controlling transactions Note: Before starting this practice. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Practices for Lesson 10: Overview Lesson Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved.sql script. execute /home/oracle/labs/sql1/code_ex /cleanup_scripts/cleanup_10. Practices for Lesson 10: Manipulating Data Chapter 10 .

you use the MY_EMPLOYEE table before giving the statements to the HR department. For SELECT queries.Page 3 y onl . All rights reserved. use the Run Script icon (or press F5) to execute the query. Oracle and/or its affiliates. continue to use the Execute Statement icon or press F9 to get the formatted output on the Results tabbed page.sql script from /home/oracle/labs/sql1/code_ex /cleanup_scripts/ before performing the following tasks. Oracle and/or its affiliatesฺ Overview The HR department wants you to create SQL statements to insert.Practice 10-1: Managing Tables by Using DML Statements Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Describe the structure of the MY_EMPLOYEE table to identify the column names. Thus. • Execute cleanup_10. Notes • For all the DML statements. you get to see the feedback messages on the Script Output tabbed page. Practices for Lesson 10: Manipulating Data Chapter 10 . and delete employee data. 2. update. e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. As a prototype. Create a table called MY_EMPLOYEE. Tasks ฺ 1.

Oracle and/or its affiliatesฺ 3. Practices for Lesson 10: Manipulating Data Chapter 10 . This time. 7. Do not list the columns in the INSERT clause. Confirm your additions to the table. 8.sql file.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Do not enter all rows yet. All rights reserved. 10. The script should prompt for all the columns (ID. LAST_NAME. Save this script to a lab_10_06. e P c e t er ib C d n a sity r e niv U e l ac 6. 9. USERID. ID LAST_NAME FIRST_NAME USERID SALARY 1 Patel Ralph rpatel 895 2 Dancs Betty bdancs 860 3 Biri Ben bbiri 1100 4 Newman Chad cnewman 750 ฺ 5 Ropeburn Audrey aropebur 1550 e us ฺ ฺC y onl ฺA S ru 4. Populate the MY_EMPLOYEE table with the second row of the sample data from the preceding list. Or Update and delete data in the MY_EMPLOYEE table. list the columns explicitly in the INSERT clause. Create an INSERT statement to add the first row of data to the MY_EMPLOYEE table from the following sample data. Change the last name of employee 3 to Drexler. Make the data additions permanent. Oracle and/or its affiliates. Copyright © 2014.Page 4 . Populate the table with the next two rows of the sample data listed in step 3 by running the INSERT statement in the script that you created. FIRST_NAME. Write an INSERT statement in a dynamic reusable script file to load the remaining rows into the MY_EMPLOYEE table. 5. Confirm your addition to the table. and SALARY).

y onl ฺA S ru 16.Page 5 . Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. ฺ 15. Change the salary to $1. 22. Confirm your changes to the table. 23. Make the data addition permanent. n a sity r e niv U e l ac Or 18. 14. Populate the table with the last row of the sample data listed in step 3 by using the statements in the script that you created in step 6. Confirm that the table is empty. Delete Betty Dancs from the MY_EMPLOYEE table. Run the statements in the script. Oracle and/or its affiliates. e us ฺ ฺC Control the data transaction to the MY_EMPLOYEE table. 20. Delete all the rows from the MY_EMPLOYEE table. 19. 21. ib C d 17. Confirm your addition to the table.000 for all employees who have a salary less than $900. Discard the most recent DELETE operation without discarding the earlier INSERT operation. Confirm that the new row is still intact. e P c e t er Note: Perform the steps (17-23) in one session only. All rights reserved. Commit all pending changes. Copyright © 2014. Mark an intermediate point in the processing of the transaction. Verify your changes to the table. 13. Practices for Lesson 10: Manipulating Data Chapter 10 .11. Oracle and/or its affiliatesฺ 12.

complete the following exercise: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. 25. Save this script to a file named lab_10_24.sql script to insert the following record: ID LAST_NAME FIRST_NAME USERID SALARY 6 Anthony Mark manthony 1230 26. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. the script should not prompt for the USERID. Modify the lab_10_06. Confirm that the new row was added with the correct USERID. Oracle and/or its affiliatesฺ 24.sql.sql script such that the USERID is generated automatically by concatenating the first letter of the first name and the first seven characters of the last name. Practices for Lesson 10: Manipulating Data Chapter 10 . The generated USERID must be in lowercase.If you have time. Therefore. Run the lab_10_24.Page 6 y onl . Oracle and/or its affiliates.

last_name. This time. 'rpatel'. Practices for Lesson 10: Manipulating Data Chapter 10 . last_name VARCHAR2(25). 860). All rights reserved. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Solution 10-1: Managing Tables by Using DML Statements Insert data into the MY_EMPLOYEE table. ฺ y onl Create an INSERT statement to add the first row of data to the MY_EMPLOYEE table from the following sample data. Do not list the columns in the INSERT clause. Populate the MY_EMPLOYEE table with the second row of the sample data from the preceding list. 2. 'Betty'. Oracle and/or its affiliates. userid. DESCRIBE my_employee 3. first_name. 895). userid VARCHAR2(8). 'Dancs'. e ID LAST_NAME FIRST_NAME 1 Patel Ralph us ฺ ฺC ฺA S ru USERID SALARY e P c e t er ib C d nBetty a sity rpatel 895 bdancs 860 2 Dancs 3 Biri Ben bbiri 1100 Newman Chad cnewman 750 Ropeburn Audrey aropebur 1550 r le U c Ora4 5 e niv INSERT INTO my_employee VALUES (1. Describe the structure of the MY_EMPLOYEE table to identify the column names. 4.Page 7 . salary) VALUES (2. 'bdancs'. Create a table called MY_EMPLOYEE. Oracle and/or its affiliatesฺ 1.2)). first_name VARCHAR2(25). salary NUMBER(9. CREATE TABLE my_employee (id NUMBER(4) CONSTRAINT my_employee_id_pk PRIMARY Key. 'Ralph'. INSERT INTO my_employee (id. 'Patel'. Copyright © 2014. list the columns explicitly in the INSERT clause.

r e niv COMMIT. All rights reserved. Confirm your additions to the table. USERID. Oracle and/or its affiliatesฺ SELECT FROM 6.Page 8 y onl . UPDATE SET WHERE e us ฺ ฺC SELECT * FROM my_employee. '&p_userid'. 11. Change the salary to $1. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. FIRST_NAME. 9. Write an INSERT statement in a dynamic reusable script file to load the remaining rows into the MY_EMPLOYEE table. ฺ my_employee salary = 1000 salary < 900. Populate the table with the next two rows of the sample data listed in step 3 by running the INSERT statement in the script that you created. The script should prompt for all the columns (ID. Oracle and/or its affiliates.5. INSERT INTO my_employee VALUES (&p_id. '&p_userid'.000 for all employees with a salary less than $900. '&p_first_name'. Change the last name of employee 3 to Drexler. '&p_last_name'.sql. and SALARY). U e l ac Or Update and delete data in the MY_EMPLOYEE table. Confirm your additions to the table. '&p_last_name'. 7. Copyright © 2014. 8. &p_salary). &p_salary). * my_employee. LAST_NAME. '&p_first_name'. INSERT INTO my_employee VALUES (&p_id. Save this script to a file named lab_10_06. ฺA S ru e P c e t er ib C d n a sity Make the data additions permanent. Practices for Lesson 10: Manipulating Data Chapter 10 . 10. UPDATE SET WHERE my_employee last_name = 'Drexler' id = 3.

Copyright © 2014. '&p_first_name'. SELECT FROM * my_employee. 19. Confirm your addition to the table. e us ฺ ฺC COMMIT. '&p_userid'. Practices for Lesson 10: Manipulating Data Chapter 10 . Verify your changes to the table. Control the data transaction to the MY_EMPLOYEE table. '&p_last_name'. ib C d n a sity INSERT INTO my_employee VALUES (&p_id. &p_salary). Oracle and/or its affiliates. Delete Betty Dancs from the MY_EMPLOYEE table. ฺA S ru e P c e t er y onl 16.Page 9 . ฺ 15. 13. Commit all pending changes. DELETE FROM my_employee. Oracle and/or its affiliatesฺ SELECT FROM * my_employee. 18. Mark an intermediate point in the processing of the transaction. 14. SELECT FROM * my_employee. r e niv U e l ac Or Note: Perform the steps (17-23) in one session only.12. Confirm your changes to the table. DELETE FROM my_employee WHERE last_name = 'Dancs'. SAVEPOINT step_17. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Run the statements in the script. All rights reserved. Delete all the rows from the MY_EMPLOYEE table. Populate the table with the last row of the sample data listed in step 3 by using the statements in the script that you created in step 6. 17.

The generated USERID must be in lowercase. n U lower(substr('&p_first_name'. not e P prompt for the USERID. Ora If you have time. COMMIT. Discard the most recent DELETE operation without discarding the earlier INSERT operation. Confirm that the table is empty. ive '&&p_last_name'. &p_salary).sql script such that the USERID is generated A ฺ Scharacters of the last concatenating the first letter of the first name and the first seven u r name. r e ib SET ECHO OFF C SET VERIFY OFF nd a INSERT INTO my_employee ity s r VALUES (&p_id. SELECT * FROM my_employee. Oracle and/or its affiliates.sql script to insert the following record: ID LAST_NAME FIRST_NAME USERID SALARY 6 Anthony Mark manthony 1230 Copyright © 2014. 21. ฺ y onl use ฺ ฺCautomatically by Modify the lab_10_06. 7)). Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. 1. ROLLBACK TO step_17. Oracle and/or its affiliatesฺ SELECT * FROM my_employee. The script should. 23. '&&p_first_name'. 1. Practices for Lesson 10: Manipulating Data Chapter 10 . Save this script to a file named tec lab_10_24. All rights reserved.Page 10 . Run the lab_10_24. therefore. Confirm that the new row is still intact.sql. Make the data addition permanent. 22. complete the following exercise: 24. SET VERIFY ON SET ECHO ON UNDEFINE p_first_name UNDEFINE p_last_name 25. 1) || e l csubstr('&p_last_name'.20.

Oracle and/or its affiliatesฺ SELECT * FROM my_employee WHERE ID='6'.Page 11 y onl . Practices for Lesson 10: Manipulating Data Chapter 10 . Confirm that the new row was added with the correct USERID. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.26. All rights reserved. Oracle and/or its affiliates. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.

Oracle and/or its affiliatesฺ ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates.Page 12 y onl . All rights reserved. Practices for Lesson 10: Manipulating Data Chapter 10 .

Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 1 . All rights reserved. Practices for Lesson 11: Using DDL Statements to Create and Manage Tables Chapter 11 . Oracle and/or its affiliatesฺ ฺ e y onl s u11: Practices for Lesson ฺ ฺC A Using DDL Statements to ฺ S Create and eruManage Tables nd a ty P c e t Chapter er 11 b i C i rs e v i n U e l c Ora Copyright © 2014.

Practices for Lesson 11: Overview
Lesson Overview

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

This practice covers the following topics:

Creating new tables

Creating a new table by using the CREATE TABLE AS syntax

Verifying that tables exist

Altering tables

Adding columns

Dropping columns

Setting a table to read-only status

Dropping tables

e

us

ฺC

ฺA
S
ru

e

P
c
e
t
er

ib
C
d

n

a
sity

r

e
niv

U
e
l
ac

Or

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11: Using DDL Statements to Create and Manage Tables
Chapter 11 - Page 2

y
onl

Note: Before starting this practice, execute the
/home/oracle/labs/sql1/code_ex/cleanup_scripts/cleanup_11.sql script.

Practice 11-1: Introduction to Data Definition Language

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

Overview
In this practice, you create new tables by using the CREATE TABLE statement. Confirm that the
new table was added to the database. You also learn to set the status of a table as READ ONLY,
and then revert to READ/WRITE. You use the ALTER TABLE command to modify table columns.
Notes

For all the DDL and DML statements, click the Run Script icon (or press F5) to execute
the query in SQL Developer. Thus, you get to see the feedback messages on the Script
Output tabbed page. For SELECT queries, continue to click the Execute Statement icon
or press F9 to get the formatted output on the Results tabbed page.

Execute the cleanup_11.sql script from
/home/oracle/labs/sql1/code_ex/cleanup_scripts/cleanup_11.sql
before performing the following tasks.

Tasks
1.

y
onl

Create the DEPT table based on the following table instance chart. Save the statement in
the lab_11_01.sql script, and then execute the statement in the script to create the
table. Confirm that the table is created.

e

Column Name

ID

Key Type

Primary key

Nulls/Unique

ฺA
S
ru
NAME

e

P
c
e
t
er

ib
C
d

FK Table

n
a
y
sit NUMBER

FK Column

er
v
i
n

Data type
Length

us

ฺC

U
e
l
c

7

VARCHAR2
25

Ora

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11: Using DDL Statements to Create and Manage Tables
Chapter 11 - Page 3

2. Create the EMP table based on the following table instance chart. Save the statement in the
lab_11_02.sql script, and then execute the statement in the script to create the table.
Confirm that the table is created.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

Column Name ID

LAST_NAME

FIRST_NAME

DEPT_ID

Key Type
Nulls/Unique
FK Table

DEPT

FK Column

ID

Data type

NUMBER

VARCHAR2

VARCHAR2

NUMBER

Length

7

25

25

7

e

us

ฺC

y
onl

ฺA
S
ru

e

P
c
e
t
er

ib
C
d

3. Modify the EMP table. Add a COMMISSION column of the NUMBER data type, with precision 2
and scale 2. Confirm your modification.

n

a
sity

r

e
niv

U
e
l
ac

Or

4. Modify the EMP table to allow for longer employee last names. Confirm your modification.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11: Using DDL Statements to Create and Manage Tables
Chapter 11 - Page 4

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

5. Drop the FIRST_NAME column from the EMP table. Confirm your modification by checking
the description of the table.

6. In the EMP table, mark the DEPT_ID column as UNUSED. Confirm your modification by
checking the description of the table.

e

us

ฺC

ฺA
S
ru

e

P
c
e
t
er

7. Drop all the UNUSED columns from the EMP table.

y
onl

ib
C
d

8. Create the EMPLOYEES2 table based on the structure of the EMPLOYEES table. Include only
the EMPLOYEE_ID, FIRST_NAME, LAST_NAME, SALARY, and DEPARTMENT_ID columns.
Name the columns in your new table ID, FIRST_NAME, LAST_NAME, SALARY, and
DEPT_ID, respectively.

n

a
sity

r

e
niv

U
e
l
ac

Or

9. Alter the status of the EMPLOYEES2 table to read-only.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11: Using DDL Statements to Create and Manage Tables
Chapter 11 - Page 5

10. Try to add a column JOB_ID in the EMPLOYEES2 table.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012, Oracle and/or its affiliatesฺ

Note: You will get the “Update operation not allowed on table” error message. You will not
be allowed to add any column to the table because it is assigned a read-only status.

11. Revert the EMPLOYEES2 table to read/write status. Now try to add the same column again.
Now, because the table is assigned a READ WRITE status, you will be allowed to add a
column to the table.

e

You should get the following messages:

us

ฺC

ฺA
S
ru

e

P
c
e
t
er

ib
C
d

n

a
sity

r

e
niv

U
e
l
ac

Or

12. Drop the EMP, DEPT, and EMPLOYEES2 table.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11: Using DDL Statements to Create and Manage Tables
Chapter 11 - Page 6

y
onl

Practices for Lesson 11: Using DDL Statements to Create and Manage Tables Chapter 11 . y onl ฺA S To confirm that the table was created and to view its structure.sql. Oracle and/or its affiliatesฺ 1. Save the statement in a script called lab_11_01.Solution 11-1: Introduction to Data Definition Language Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. eru issue the following command: P DESCRIBE dept. Confirm that the table is created. us ฺ ฺC 2. and then execute the statement in the script to create the table.sql. Create the DEPT table based on the following table instance chart. Save the statement in a Create the EMP table based on the d following n then execute the statement in the script to create the script called lab_11_02.Page 7 . Column Name ID Key Type Primary key NAME Nulls/Unique FK Table FK Column Data type NUMBER VARCHAR2 Length 7 25 ฺ e CREATE TABLE dept (id NUMBER(7)CONSTRAINT department_id_pk PRIMARY KEY. last_name VARCHAR2(25). tec r e Cib table instance chart. first_name VARCHAR2(25). Copyright © 2014.a and y table. Oracle and/or its affiliates. dept_id NUMBER(7) CONSTRAINT emp_dept_id_FK REFERENCES dept (id) ). Confirm that the table sit is created. name VARCHAR2(25)). r e niv U LAST_NAME FIRST_NAME DEPT_ID Column e Name ID l c a Type OrKey Nulls/Unique FK Table DEPT FK Column ID Data type NUMBER VARCHAR2 VARCHAR2 NUMBER Length 7 25 25 7 CREATE TABLE emp (id NUMBER(7). All rights reserved.

DESCRIBE emp 7. ALTER TABLE emp SET UNUSED (dept_id). ALTER TABLE emp ADD commission NUMBER(2. Modify the EMP table. ALTER TABLE emp MODIFY (last_name VARCHAR2(50)). U e l c table.2). Confirm your modification. Copyright © 2014. Add a COMMISSION column of the NUMBER data type. Oracle and/or its affiliates. Drop all the UNUSED columns from the EMP table. Confirm your modification by checking the description of the table.To confirm that the table was created and to view its structure: DESCRIBE emp Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Confirm your modification. ib C d ALTER TABLE emp DROP COLUMN first_name. DESCRIBE emp 4. Practices for Lesson 11: Using DDL Statements to Create and Manage Tables Chapter 11 . DESCRIBE emp n a sity r e niv 6. Drop the FIRST_NAME column from the EMP table. Modify the EMP table to allow for longer employee last names. mark the DEPT_ID column as UNUSED. ALTER TABLE emp DROP UNUSED COLUMNS. with precision 2 and scale 2. Oracle and/or its affiliatesฺ 3. Confirm your modification by In the EMP checking Ora the description of the table. ฺ e us ฺ ฺC DESCRIBE emp y onl ฺA S ru e P c e t er 5. All rights reserved.Page 8 .

10. last_name. Drop the EMP.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. ฺ Note: You will get the “Update operation not allowed on table” error message. Confirm that the table is created. DESCRIBE employees2 9. first_name. Alter the EMPLOYEES2 table status to read-only. Copyright © 2014. y onl ฺA S ru e P c e t er 11. The tables will be dropped. respectively. Oracle and/or its affiliatesฺ 8. SALARY. e us ฺ ฺC ALTER TABLE employees2 ADD job_id VARCHAR2(9). and then issue the DROP TABLE command. Include only the EMPLOYEE_ID. Now try to add the same column again. FIRST_NAME. salary. because the table is assigned a READ WRITE status. DROP TABLE emp. DEPT. DROP TABLE dept. All rights reserved. and DEPARTMENT_ID columns. Revert the EMPLOYEES2 table to the read/write status. ALTER TABLE employees2 READ ONLY. Create the EMPLOYEES2 table based on the structure of the EMPLOYEES table. Name the columns in your new table ID. SALARY. alter the table again to READ ONLY status. Practices for Lesson 11: Using DDL Statements to Create and Manage Tables Chapter 11 . n a sity r e niv ALTER TABLE employees2 READ WRITE. CREATE TABLE employees2 AS SELECT employee_id id. U e l ac ALTER TABLE employees2 ADD job_id VARCHAR2(9). you will be allowed to add a column to the table. DROP TABLE employees2. LAST_NAME. DESCRIBE employees2 Or 12. LAST_NAME. Oracle and/or its affiliates. Try to add a column JOB_ID in the EMPLOYEES2 table. department_id dept_id FROM employees. To test this. ib C d Now. and DEPT_ID. FIRST_NAME. Note: You can even drop a table that is in READ ONLY mode. You will not be allowed to add any column to the table because it is assigned a read-only status. and EMPLOYEES2 table.Page 9 .

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliatesฺ ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. All rights reserved.Page 10 y onl . Oracle and/or its affiliates. Practices for Lesson 11: Using DDL Statements to Create and Manage Tables Chapter 11 .

Page 1 y onl . Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliatesฺ ฺ e s uand Additional Practices ฺ C Solutions SฺAฺ ru e cP Chapter 12 te nd a ty er b i C i rs e v i n U e l c Ora Copyright © 2014.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Oracle and/or its affiliates.

Oracle and/or its affiliates. Oracle and/or its affiliatesฺ In these practices. you will be working on extra exercises that are based on the following topics: • Basic SQL SELECT statement • • Basic SQL Developer commands SQL functions ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014.Practices for Lesson 1 Practices Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved.Page 2 y onl . Additional Practices and Solutions Chapter 12 .

Sort the data by salary in descending order. but who have a 10% raise in salary (round off the salaries). The report should display those employees who have no commission. and commission of these employees. and SQL functions. 2. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er 3. Show the last name. job.Page 3 . Oracle and/or its affiliates. the HR department needs a report on projected raises. The HR department needs a report of employees who earn a commission. salary. Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliatesฺ Overview In this practice. ib C d For budgeting purposes. All rights reserved. The HR department needs to find data for all the clerks who were hired after 1997. basic SQL Developer commands. Tasks 1. exercises have been designed to be worked on after you have discussed the following topics: basic SQL SELECT statement.Practice 1-1: Additional Practice Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. n a sity r e niv U e l ac Or Copyright © 2014.

” “L. Create a report of employees and their duration of employment.Page 4 . Oracle and/or its affiliates. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er 5. ib C d n a sity Show those employees who have a last name starting with the letters “J.” r e niv U e l ac Or Copyright © 2014.” or “M.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.” “K. All rights reserved. Order the report by the duration of their employment. The employee who has been employed the longest should appear at the top of the list. Oracle and/or its affiliatesฺ 4. Show the last names of all the employees together with the number of years and the number of completed months that they have been employed. Additional Practices and Solutions Chapter 12 .

SQL functions.Page 5 . Use the DECODE expression in your query. Additional Practices and Solutions Chapter 12 . joins. Prompt the user for a location. Create a report that displays all employees. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity r e niv These exercises can be used for extra practice after you have discussed the following topics: basic SQL SELECT statements. and group functions. Create a report that displays the department name. last name. U e l ac Or 7. All rights reserved.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. and salary of those employees who work in a specific location. Oracle and/or its affiliatesฺ 6.” Create two possible solutions. results are as follows: 8. Oracle and/or its affiliates. and indicate with the words Yes or No whether they receive a commission. job title. if the user enters 1800. Copyright © 2014. For example. Find the number of employees who have a last name that ends with the letter “n. location ID. basic SQL Developer commands.

location. Show the job with the highest number of employees first. and number of employees for each department.Page 6 . Also display the number of employees for these jobs. Additional Practices and Solutions Chapter 12 . ฺ e us ฺ ฺC y onl ฺA S ru 11. e P c e t er ib C d n a sity r e niv U e l c Theseaexercises can be used for extra practice after you have discussed the following topics: Or basic SQL SELECT statements. 12. All rights reserved. group functions. Make sure that the report also includes department_IDs without employees. joins. SQL functions.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. irrespective of the year). Oracle and/or its affiliatesฺ 9. and subqueries. basic SQL Developer commands. Create a report that shows the name. Create a report to display the job IDs for those departments. Oracle and/or its affiliates. Create a report that displays the jobs that are found in the Administration and Executive departments. Show all the employees who were hired in the first half of the month (before the 16th of the month. The HR department needs to find the job titles in departments 10 and 20. Copyright © 2014. 10.

ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er 14.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. manager salary. salary. ib C d Show all the employees who havenmanagers with a salary higher than $15. Show the a following data: employee name. All rights reserved. Create a report that displays the following for all employees: last name. r ive n U e l c Ora Copyright © 2014. Oracle and/or its affiliatesฺ 13.000. ity manager name. Oracle and/or its affiliates. and salary grade of the s manager. Additional Practices and Solutions Chapter 12 .Page 7 . and salary expressed in terms of thousands of dollars.

All rights reserved. Create a report to display the department number and lowest salary of the department with the highest average salary. name. Or Copyright © 2014.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d 16. department name. manager ID. Oracle and/or its affiliatesฺ 15. together with the names. Create a report that displays departments where no sales representatives work. Oracle and/or its affiliates. Show the department number. and location in the output. Include the department number. Additional Practices and Solutions Chapter 12 . n a sity r e niv U e l ac 17. number of employees. and average salary of all the departments.Page 8 . salaries. and jobs of the employees working in each department.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. and the number of employees working in each department that: a. last name. salary. Has the highest number of employees: c. department number. Additional Practices and Solutions Chapter 12 . Include the department number. Has the lowest number of employees: ฺ y onl 19. Create a report that displays the employee number. e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. department name. Create the following statistical reports for the HR department. Employs fewer than three employees: b. All rights reserved.Page 9 . and the average salary in their department for all employees. Oracle and/or its affiliatesฺ 18. Oracle and/or its affiliates.

ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Sort the anniversaries in ascending order. Create an anniversary overview based on the hire date of the employees. Oracle and/or its affiliatesฺ 20.Page 10 y onl .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliates.

job. job_id. ฺ SELECT last_name. e us ฺ ฺC y onl ฺA S ru 3. 12)) MONTHS FROM employees ORDER BY years DESC. Oracle and/or its affiliatesฺ Solutions to Additional Practice 1-1 are given as follows. Pe c rte a report on projected raises. n y ofa '||last_name||' after a 10% raise is ' t i SELECT 'The salary s r eROUND(salary*1. The report For budgeting purposes. Sort the data by salary in descending order. OWHERE Create a report of employees and the duration of their employment.10) v i || "New salary" n U FROMle employees rac commission_pct IS NULL. The HR department needs a report of employees who earn a commission. Order the report by the duration of their employment. Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliates. Show the last name. MONTHS desc. salary. SELECT * FROM employees WHERE job_id = 'ST_CLERK' AND hire_date > '31-DEC-1997'. hire_date) / 12) YEARS. All rights reserved. TRUNC(MOD(MONTHS_BETWEEN(SYSDATE. Copyright © 2014. The employee who has been employed the longest should appear at the top of the list.Page 11 . commission_pct FROM employees WHERE commission_pct IS NOT NULL ORDER BY salary DESC. and commission of these employees. The HR department needs to find data for all the clerks who were hired after 1997. together with the number of years and the number of completed months that they have been employed. SELECT last_name. 4. hire_date). Tasks 1.Solution 1-1: Additional Practice Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Show the last names of all employees. 2. salary. the HR departmenteneeds b i get a commission but who have a 10% raise in should display those employees who do Cnot d salary (round off the salaries). TRUNC(MONTHS_BETWEEN(SYSDATE.

Use the DECODE expression in your query. COUNT(*) employees SUBSTR(last_name.department_id GROUP BY d. employees last_name LIKE '%n'. 'L'. d. d. le c a r COUNT(*) OSELECT FROM WHERE --or SELECT FROM WHERE 9. 'No'. 6. SELECT d. joins. 1. job title. Additional Practices and Solutions Chapter 12 . and group functions. last name.” “L.location_id. ฺ y l n Create a report that displays the department name.department_id. Create a report that shows the name. basic SQL Developer commands.Page 12 . 'M'). Show those employees who have a last name that starts with the letters “J. 'Yes') commission FROM employees. NULL.department_id = d.1) IN ('J'. 7.last_name.job_id.department_id = d. SELECT last_name.” or “M. ฺA S SELECT d.” Create U two possible solutions.department_name. o and ea location.location_id a y sit r e Find the numbern ofiv employees who have a last name that ends with the letter “n. Copyright © 2014.rue.5. COUNT(e. -1) = 'n'. All rights reserved. These exercises can be used for extra practice after you have discussed the following topics: basic SQL SELECT statement. Oracle and/or its affiliates. and indicate with the words Yes or No whether they receive a commission. d.department_name. e. d. SQL functions. d. location ID. and number of employees for each department.salary Pe c FROM employees e JOIN departments rte d e b ON e. salary of those employees who work in a specific location. Prompt the userufor s ฺ C ฺ Enter 1800 for location_id when prompted. e.department_name.employee_id) FROM employees e RIGHT OUTER JOIN departments d ON e. Make sure that the report also includes department_IDs without employees.location_id.department_id Ci d n= &location_id. salary.” Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Create a report that displays all employees. location. 8.location_id. decode(commission_pct. 'K'. Oracle and/or its affiliatesฺ SELECT last_name FROM employees WHERE SUBSTR(last_name.” “K. AND d.department_id.

salary. count(e. Show the job with the highest number of employees first. All rights reserved. Create a report to display the job IDs for these departments. Pe c te of the month (before the 16th of the rhalf e Show all employees who were hired in thebfirst Ci month. d an SELECT last_name. TRUNC(salary. SELECT last_name. joins.job_id) FREQUENCY FROM employees e JOIN departments d ON e.last_name.Page 13 . Show all employees who have managers with a salary higher than $15. 'Executive') GROUP BY e.000.salary BETWEEN j.manager_id = m. basic SQL Developer commands. manager name. and salary grade of the manager. group functions. 'DD') < 16. manager salary.lowest_sal AND j. -3)/1000 FROM employees. Oracle and/or its affiliates.salary > 15000. m. salary. 13. and subqueries. SQL functions. and salary Create expressed in terms of thousands of dollars. e cl a r O a report that displays the following for all employees: last name.grade_level FROM employees e JOIN employees m ON e.last_name manager. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.tyhire_date si r FROM employees e niv WHERE U TO_CHAR(hire_date. Also display the number of employees for these jobs. j. ฺA S ru 12.department_name IN ('Administration'. 20). 11.department_id = d. Show the following data: employee name. Copyright © 2014.highest_sal AND m. SELECT e. Oracle and/or its affiliatesฺ SELECT DISTINCT job_id FROM employees WHERE department_id IN (10.job_id.10.department_id WHERE d.job_id ORDER BY FREQUENCY DESC.employee_id JOIN job_grades j ON m.salary. Thousands 14. m. irrespective of the year). Create a report that displays the jobs that are found in the Administration and Executive departments. Additional Practices and Solutions Chapter 12 . The HR department needs to find the job titles in departments 10 and 20. e us ฺ ฺC ฺ y onl These exercises can be used for extra practice after you have discussed the following topics: basic SQL SELECT statements. SELECT e.

Show the department number.job_id FROM departments d RIGHT OUTER JOIN employees e1 ON d. and location in the output. Copyright © 2014. e2. ive n U e l c Create Oraa report that displays the departments where no sales representatives work. All rights reserved. ฺ y onl 16. employees. manager ID. Additional Practices and Solutions Chapter 12 . SELECT * FROM departments WHERE department_id NOT IN(SELECT department_id FROM employees WHERE job_id = 'SA_REP' AND department_id IS NOT NULL). MIN(salary) P FROM employees tec r e GROUP BY department_id ib C HAVING AVG(salary) = (SELECT MAX(AVG(salary)) nd a ity FROM employees s r GROUP BY department_id). e2.department_id = e1. and average salary of all departments. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.salary).employee_id) employees. S eru SELECT department_id.salary.15. 17. se u ฺ Create a report to display the department number and lowest salary ฺofCthe department with ฺA the highest average salary. NVL(TO_CHAR(AVG(e1.department_name.department_name. e2. together with the names. department name.last_name. name. '99999.department_id = e2.department_id. Include the department number. number of employees. d. count(e1.department_id.last_name. Oracle and/or its affiliatesฺ SELECT d. d. 'No average' ) avg_sal.99'). e2.Page 14 . salaries. and jobs of the employees working in each department.department_id.job_id ORDER BY d. e2.salary.department_id RIGHT OUTER JOIN employees e2 ON d. e2. Oracle and/or its affiliates.department_id GROUP BY d.

department_id GROUP BY d. ฺ e us ฺ ฺC c. All rights reserved.department_id = e.department_id = e. SELECT e.department_id. COUNT(*) FROM departments d JOIN employees e ON d.department_id. d.18. Has the lowest number of employees: y onl ฺA S ru e P c e t er SELECT d.department_name HAVING COUNT(*) = (SELECT MIN(COUNT(*)) FROM employees GROUP BY department_id). e. Has the highest number of employees: SELECT d. e. d.last_name.employee_id.department_id GROUP BY e. d. e. e.department_id = e.department_id GROUP BY d. d. and the number of employees working in each department that: Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. department name. Oracle and/or its affiliatesฺ a.last_name. d.department_id.salary.salary) FROM employees e JOIN employees s ON e.department_name HAVING COUNT(*) < 3.department_id.department_id GROUP BY d. department number. b.department_name.Page 15 . COUNT(*) FROM departments d JOIN employees e ON d. and the average salary in their department for all employees. AVG(s. last name.department_name. Include the department number. Create the following statistical reports for the HR department. COUNT(*) FROM departments d JOIN employees e ON d. salary.department_name HAVING COUNT(*) = (SELECT MAX(COUNT(*)) FROM employees GROUP BY department_id). d. e.department_id.department_id = s. e. Copyright © 2014. Create a report that displays the employee number.department_name. ib C d n a sity r e niv U e l ac Or 19.department_id.department_id. Employs fewer than three employees: SELECT d.department_id. Oracle and/or its affiliates.salary.employee_id. Additional Practices and Solutions Chapter 12 .

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved.20. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Sort the anniversaries in ascending order. 'DDD'). TO_CHAR(hire_date. Oracle and/or its affiliatesฺ SELECT last_name. Oracle and/or its affiliates. Additional Practices and Solutions Chapter 12 .Page 16 y onl . Create an anniversary overview based on the hire date of employees. 'Month DD') BIRTHDAY FROM employees ORDER BY TO_CHAR(hire_date.

Copyright © 2014. • If you use the Online_Book_Store_Drop_Tables. Oracle and/or its affiliatesฺ Overview In this case study. you can execute the commands in the Online_Book_Store_Drop_Tables.sql script to build and populate the tables. start with step 6. Additional Practices and Solutions Chapter 12 . start with step 2. start with step 1.sql>> script in SQL Developer to create and populate the tables. you insert.sql script in SQL Developer. and delete records in the book store database and generate a report. you can execute the commands in the Online_Book_Store_Create_Table. The database contains only the essential tables. After you create the tables. • If you use the Online_Book_Store_Populate.sql script to build the tables. • If you use the Online_Book_Store_Create_Table. All rights reserved.sql script in SQL Developer. If you want to drop the tables. Then you can execute the commands in the <<Online_Book_Store_Populate.Page 17 .Case Study: Online Book Store Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. The following is a diagram of the table and columns for the online book store application: ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Note: If you want to build the tables.sql script to remove the tables. All the three SQL scripts are present in the /home/oracle/labs/sql1/labs folder. you build a set of database tables for an online book store (E-Commerce Shopping Cart). Oracle and/or its affiliates. update.

Oracle and/or its affiliates. Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliatesฺ In this practice. you create the tables based on the following table instance charts. Data type VARCHAR2 VARCHAR2 Table Dependent Type Key PK Table Dependent On FK AUTHORS FK PUBLISHER Table Name: BOOKS Column Book_ID Book_Name Author_ID Price Publisher_ID c. Key PK Datatype VARCHAR2 VARCHAR2 VARCHAR2 NUMBER VARCHAR2 e Data type VARCHAR2 VARCHAR2 VARCHAR2 VARCHAR2 VARCHAR2 VARCHAR2 Or ฺA S ru ib PK C d Table Dependent On n a sity r e niv U e l ac us ฺ ฺC e P c e t r eKey Table Name: CUSTOMER Column Name Customer_ID Customer_Name Street_Address City Phone_Number Credit_Card_Number ฺ FK Credit_Card_Details d. Table Details a. Tasks 1.Page 18 . All rights reserved.Practice 1-2 Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Data type VARCHAR2 VARCHAR2 DATE Key PK Table Dependent On Table Name: ORDER_DETAILS Column Order_ID Customer_ID Shipping_Type Date_of_Purchase Shopping_Cart_ID y onl Data type NUMBER VARCHAR2 VARCHAR2 DATE NUMBER Key PK FK FK Table Dependent On CUSTOMER SHIPPING_TYPE FK SHOPPING_CART Copyright © 2014. CREDIT_CARD_DETAILS Column Name Credit_Card_Number Credit_Card_Type Expiry_Date e. Table Name: AUTHOR Column Author_ID Author_Name b. Select the appropriate data types and be sure to add integrity constraints.

U e l ac Start with 100. Oracle and/or its affiliatesฺ f. n a sity r e niv a. Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Key FK FK Table Dependent Type Table Dependent Type CUSTOMER ORDER_DETAILS Table Name: SHIPPING_TYPE Column Shipping_Type Shipping_Price Data type VARCHAR2 NUMBER i. Table Name: SHOPPING_CART Column Data type Shopping_Cart_ID NUMBER Book_ID VARCHAR2 Price NUMBER Date DATE Quantity NUMBER Key PK Table Dependent Type Key PK FK Table Dependent On e us ฺ ฺC BOOKS ฺ y onl ฺA S ru e P c e t er ib C d 2. do not allow caching of the values. Create a sequence to uniquely identify each row in the ORDER_DETAILS table. Table Name: PUBLISHER Column Data type Publisher_ID VARCHAR2 Publisher_Name VARCHAR2 Key PK g. Or Copyright © 2014. Add additional Referential Integrity constraints to the tables created. 3. Verify that the tables were created properly by checking in the Connections Navigator in SQL Developer. All rights reserved. Name the sequence ORDER_ID_SEQ. 4. Additional Practices and Solutions Chapter 12 . Table Name: PURCHASE_HISTORY Column Data type Customer_ID VARCHAR2 Order_ID NUMBER h.Page 19 .

Oracle and/or its affiliates. y onl ฺA S ru e P c e t er Add data to the tables. Additional Practices and Solutions Chapter 12 . ฺ e us ฺ ฺC 5. Ore. PURCHASE_HISTORY Note: Save the scripts using the task number. All rights reserved. Ensure that you save the scripts in the /home/oracle/labs folder. AUTHOR b. PUBLISHER c. CREDIT_CARD_DETAILS f.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. SHOPPING_CART h. Verify the existence of the sequences in the Connections Navigator in SQL Developer. Add data to the following tables: a. you can save it as labs_apcs_5a_1. SHIPPING_TYPE ib C d n a sity r e niv U e CUSTOMER l ac d. Create a script for each set of data to be added. BOOKS g. to save the script created for the BOOKS table. ORDER_DETAILS i. Oracle and/or its affiliatesฺ b. Copyright © 2014.sql. For example.Page 20 .

Page 21 y onl .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Copyright © 2014. Make changes to the data in the tables. Oracle and/or its affiliatesฺ 6. and the details of the order placed by the customer. Verify if the author detail for the book is available in the AUTHOR table. Customer Address. If not. Add a new book detail. Oracle and/or its affiliates. Additional Practices and Solutions Chapter 12 . Create a view named CUSTOMER_DETAILS to show the Customer Name. Order the results by Customer ID. a. ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac r a shopping cart detail for the book details that you just entered in 7(a). 7. OEnter b. make an entry in the AUTHOR table. All rights reserved.

Create a report that contains each customer’s history of purchasing books. date of purchase. book ID. Oracle and/or its affiliates. Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 22 y onl . ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. customer ID.sql. Additional Practices and Solutions Chapter 12 . All rights reserved. Be sure to include the customer name. Oracle and/or its affiliatesฺ Note: Your results may be different. Save the commands that generate the report in a script file named lab_apcs_8.8. and shopping cart ID.

ALTER TABLE BOOKS ADD CONSTRAINT books_PK PRIMARY KEY ( Book_ID ). Tasks 1. BOOKS Book_ID VARCHAR2 (10) NOT NULL . Table Details a. Oracle and/or its affiliatesฺ The solution to Practice 1-2 is given as follows. Oracle and/or its affiliates. Author_Name VARCHAR2 (20) ) . Price NUMBER (10) . Book_Name VARCHAR2 (50) . All rights reserved. Author_ID VARCHAR2 (10) NOT NULL . n a sity er v i nTABLE BOOKS CREATE U e cl( a r O b. COMMENT ON TABLE BOOKS IS 'Books' . Publisher_ID VARCHAR2 (10) NOT NULL ) . Additional Practices and Solutions Chapter 12 .Page 23 y onl . Copyright © 2014. us ฺ ฺC ฺA S ru e P c e t er ib C d ALTER TABLE AUTHOR ADD CONSTRAINT AUTHOR_PK PRIMARY KEY (Author_ID). AUTHOR CREATE TABLE AUTHOR ( Author_ID VARCHAR2 (10) NOT NULL . ฺ e COMMENT ON TABLE AUTHOR IS 'Author' .Solution 1-2 Overview Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.

Customer_Name VARCHAR2 (40) . Phone_Number VARCHAR2 (15) .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Oracle and/or its affiliates. ฺA S ru e d. Copyright © 2014. COMMENT ON TABLE CUSTOMER IS 'Customer' . CUSTOMER CREATE TABLE CUSTOMER ( Customer_ID VARCHAR2 (6) NOT NULL . Credit_Card_Number VARCHAR2 (20) NOT NULL ) . n a sity r ive n U e l c NOT NULL . City VARCHAR2 (25) . All rights reserved. P c e t er CREDIT_CARD_DETAILS ib C d CREATE TABLE CREDIT_CARD_DETAILS ( Credit_Card_Number VARCHAR2 (20) Credit_Card_Type VARCHAR2 (10) . ฺ e us ฺ ฺC y onl ALTER TABLE CUSTOMER ADD CONSTRAINT Customer_PK PRIMARY KEY ( Customer_ID ) . Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliatesฺ c. Street_Address VARCHAR2 (50) .Page 24 . ALTER TABLE CREDIT_CARD_DETAILS ADD CONSTRAINT Credit_Card_Details_PK PRIMARY KEY ( Credit_Card_Number) . Ora COMMENT ON TABLE CREDIT_CARD_DETAILS IS 'Credit Card Details' . Expiry_Date DATE ) .

Customer_ID VARCHAR2 (6) NOT NULL . Oracle and/or its affiliatesฺ e. ALTER TABLE ORDER_DETAILS ADD CONSTRAINT ORDER_DETAILS_PK PRIMARY KEY (Order_ID ) . Publisher_Name VARCHAR2 (50) ) . Date_of_Purchase DATE . Shipping_Type VARCHAR2 (10) NOT NULL . ORDER_DETAILS CREATE TABLE ORDER_DETAILS ( Order_ID VARCHAR2 (6) NOT NULL . Or ALTER TABLE PUBLISHER ADD CONSTRAINT PUBLISHER_PK PRIMARY KEY ( Publisher_ID) . Oracle and/or its affiliates. e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac COMMENT ON TABLE PUBLISHER IS 'Publisher' . PUBLISHER CREATE TABLE PUBLISHER ( Publisher_ID VARCHAR2 (10) NOT NULL . Copyright © 2014. COMMENT ON TABLE ORDER_DETAILS IS 'Order Details' . Additional Practices and Solutions Chapter 12 .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Shopping_Cart_ID varchar2(6) NOT NULL ) .Page 25 ฺ y onl . All rights reserved. f.

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Ci d n a y ALTER TABLE SHIPPING_TYPE sit r e ADD CONSTRAINT SHIPPING_TYPE_PK PRIMARY niv U ) . Order_ID VARCHAR2 (6) NOT NULL ) . ฺ NOT NULL . COMMENT ON TABLE PURCHASE_HISTORY IS 'Purchase History' . Oracle and/or its affiliatesฺ g. All rights reserved. SHIPPING_TYPE CREATE TABLE SHIPPING_TYPE ( Shipping_Type VARCHAR2 (10) Shipping_Price NUMBER (6) ) . h. le c a Or Copyright © 2014. Additional Practices and Solutions Chapter 12 . ฺA S ru Pe c te 'Shipping COMMENT ON TABLE SHIPPING_TYPE rIS e b . PURCHASE_HISTORY CREATE TABLE PURCHASE_HISTORY ( Customer_ID VARCHAR2 (6) NOT NULL . Oracle and/or its affiliates.Page 26 e us ฺ ฺC y onl Type' KEY ( Shipping_Type .

Copyright © 2014. ALTER TABLE SHOPPING_CART ADD CONSTRAINT SHOPPING_CART_PK PRIMARY KEY (SHOPPING_CART_ID) . ฺ e 2. All rights reserved. Oracle and/or its affiliatesฺ i. us ฺ ฺC ฺA S ru Adding Additional Referential Integrity Constraints to the Table Created a. Book_ID VARCHAR2 (10) NOT NULL . Price NUMBER (10) . e P c e t er Include a Foreign Key constraint in the BOOKS table.Page 27 y onl . n a sity r e niv U e l ac Or ALTER TABLE BOOKS ADD CONSTRAINT BOOKS_PUBLISHER_FK FOREIGN KEY ( Publisher_ID ) REFERENCES PUBLISHER ( Publisher_ID ). ib C d ALTER TABLE BOOKS ADD CONSTRAINT BOOKS_AUTHOR_FK FOREIGN KEY ( Author_ID ) REFERENCES AUTHOR ( Author_ID ) . Shopping_cart_Date DATE . Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Additional Practices and Solutions Chapter 12 . Quantity NUMBER (6) ) . SHOPPING _CART CREATE TABLE SHOPPING_CART ( Shopping_Cart_ID VARCHAR2 (6) NOT NULL . COMMENT ON TABLE SHOPPING_CART IS 'Shopping Cart' .

Copyright © 2014. Include a Foreign Key constraint in the ORDER_DETAILS table. Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 28 y onl . ALTER TABLE ORDER_DETAILS ADD CONSTRAINT Order_ID_FK FOREIGN KEY ( Customer_ID ) REFERENCES CUSTOMER ( Customer_ID ) . Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliatesฺ b. All rights reserved. e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac r OALTER TABLE ORDER_DETAILS ADD CONSTRAINT Order_Details_fk FOREIGN KEY ( Shopping_Cart_ID ) REFERENCES SHOPPING_CART ( Shopping_Cart_ID ) . ฺ ALTER TABLE ORDER_DETAILS ADD CONSTRAINT FK_Order_details FOREIGN KEY ( Shipping_Type ) REFERENCES SHIPPING_TYPE ( Shipping_Type ) .

All rights reserved. ib C d Include a Foreign Key constraint in the SHOPPING_CART table. ALTER TABLE PURCHASE_HISTORY ADD CONSTRAINT Pur_Hist_ORDER_DETAILS_FK FOREIGN KEY ( Order_ID ) REFERENCES ORDER_DETAILS ( Order_ID ) . U e l ac Or Copyright © 2014. Include a Foreign Key constraint in the PURCHASE_HISTORY table. Oracle and/or its affiliatesฺ c.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. ฺ e us ฺ ฺC ฺA S ru e P c e t er d. n a sity r e niv ALTER TABLE SHOPPING_CART ADD CONSTRAINT SHOPPING_CART_BOOKS_FK FOREIGN KEY ( Book_ID ) REFERENCES BOOKS ( Book_ID ) . Oracle and/or its affiliates. ALTER TABLE PURCHASE_ HISTORY ADD CONSTRAINT Purchase_History_CUSTOMER_FK FOREIGN KEY ( Customer_ID ) REFERENCES CUSTOMER ( Customer_ID ) .Page 29 y onl . Additional Practices and Solutions Chapter 12 .

G. Wodehouse Copyright © 2014. All rights reserved. Alternatively. b.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. do not allow caching of the values. Additional Practices and Solutions Chapter 12 . a. ฺ e us ฺ ฺC Add data to the tables. Name the sequence ORDER_ID_SEQ. expand Sequences. CREATE SEQUENCE order_id_seq START WITH 100 NOCACHE.Page 30 y onl . 5. In the Connections Navigator. a. Create a sequence to uniquely identify each row in the ORDER DETAILS table. AUTHOR Table ฺA S ru Author_ID Author_Name Pe c erteOscar Wilde AN0001 Oliver Goldsmith ib C d AN0002 n AN0003 AN0004 a sity r ive n U e l AN0005 rac OAN0007 AN0006 George Bernard Shaw Leo Tolstoy Percy Shelley Lord Byron John Keats AN0008 Rudyard Kipling AN0009 P. Oracle and/or its affiliates. Verify that the tables were created properly by checking in the Connections Navigator in SQL Developer. 4. Start with 100. you can also query the user_sequences data dictionary view: SELECT * FROM user_sequences. Verify the existence of the sequences in the Connections Navigator in SQL Developer. expand Connections > myconnection > Tables. In the Connections Navigator. Oracle and/or its affiliatesฺ 3. assuming that the myconnection node is expanded.

PUBLISHER Table Publisher_ID Publisher_Name PN0001 Elsevier PN0002 Penguin Group PN0003 Pearson Education PN0004 Cambridge University Press PN0005 Dorling Kindersley ฺ e us ฺ ฺC ฺA S ru c. Oracle and/or its affiliatesฺ b. Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. Additional Practices and Solutions Chapter 12 . SHIPPING _TYPE Pe c erteShipping_Price Shipping_Type USPS y sit r e v FedEx DHL i n U e l ib C d an 200 250 150 c Ora Copyright © 2014.Page 31 y onl . All rights reserved.

Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliates. Brisbane 000-111-222-111 y sit r e v and c rte e b i ฺA S ru Pe C i n U e l c Ora Copyright © 2014. Quebec 418-542-9988 000-111-222-888 CN0007 Menchu Roberta Boulevard de Waterloo 41 Brussels 322-504-2228 CN0008 Biri Ben 398 High St. CUSTOMER Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.Page 32 e us ฺ ฺC 616-399-1411 ฺ y onl 000-111-222-999 . All rights reserved. Columbu 614-455-9863 s 000-111-222-222 CN0009 Catchpole Antoinette 88 Alfred St.d. Oracle and/or its affiliatesฺ Customer Customer _Name _ ID Street _Address City Phone _number Credit _Card _Number CN0001 VelasquezCarmen 283 King Street Seattle 587-99-6666 000-111-222-333 CN0002 Ngao LaDoris 5 Modrany Bratislav a 586-355-8882 000-111-222-444 CN0003 Nagayama Midori 68 Via Centrale Sao Paolo 254-852-5764 000-111-222-555 CN0004 Quick-To-See Mark 6921 King Way Lagos 63-559-777 000-111-222-666 CN0005 Ropeburn Audry 86 Chu Street Hong Kong 41-559-87 000-111-222-777 CN0006 Urguhart Molly 3035 Laurier Blvd.

Additional Practices and Solutions Chapter 12 .Page 33 . CREDIT_CARD_DETAILS Credit _Card_ Number Credit _Card _Type Expiry _Date 000-111-222-333 VISA 17-JUN-2009 000-111-222-444 MasterCard 24-SEP-2005 000-111-222-555 AMEX 11-JUL-2006 000-111-222-666 VISA 22-OCT-2008 000-111-222-777 AMEX 26-AUG-2000 000-111-222-888 MasterCard 15-MAR-2008 000-111-222-999 VISA 4-AUG-2009 000-111-222-111 Maestro 27-SEP-2001 000-111-222-222 AMEX 9-AUG-2004 ฺ e us ฺ ฺC y onl ฺA S ru e P c e t er ib C d n a sity r e niv f. Oracle and/or its affiliates.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. U e l ac BOOKS r _ID OBook Book _Name Author _ID Price Publisher _ID BN0001 Florentine Tragedy AN0002 150 PN0002 BN0002 A Vision AN0002 100 PN0003 BN0003 Citizen of the World AN0001 100 PN0001 BN0004 The Complete Poetical AN0001 300 PN0001 Works of Oliver Goldsmith BN0005 Androcles and the Lion AN0003 90 PN0004 BN0006 An Unsocial Socialist AN0003 80 PN0004 Copyright © 2014. Oracle and/or its affiliatesฺ e.

All rights reserved.Page 34 ฺ y onl . SHOPPING_CART Shopping _Cart _ID Book _ID Price Shopping _Cart _Date Quantity SC0001 BN0002 200 12-JUN-2001 10 SC0002 BN0003 90 31-JUL-2004 8 SC0003 BN0003 175 28-JUN-2005 7 SC0004 BN0001 80 14-AUG-2006 9 SC0005 BN0001 175 21-SEP-2006 4 SC0006 BN0004 100 11-AUG-2007 6 SC0007 BN0005 200 28-OCT-2007 5 Copyright © 2014. Oracle and/or its affiliates. Additional Practices and Solutions Chapter 12 . Oracle and/or its affiliatesฺ BN0007 A Thing of Beauty is a Joy Forever AN0007 100 PN0002 BN0008 Beyond the Pale AN0008 75 PN0005 BN0009 The Clicking of Cuthbert AN0009 175 PN0005 BN00010 Bride of Frankenstein AN0006 200 PN0001 BN00011 Shelley's Poetry and Prose AN0005 150 PN0003 BN00012 War and Peace AN0004 150 PN0002 e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or g.Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.

Oracle and/or its affiliatesฺ h. Oracle and/or its affiliates. SC0008 BN0006 100 25-NOV-2009 7 SC0009 BN0006 150 18-SPET-2009 8 ฺ ORDER _DETAILS Shopping use _Cart _ID ฺ ฺC Order _ID Customer _ID Shipping_ Type Date _of _Purchase OD0001 CN0001 USPS 12-JUN-2001 OD0002 CN0002 USPS OD0003 CN0003 FedEx OD0004 CN0004 OD0005 ity s r ve niCN0006 OD0006 U OD0007 e l rac OOD0008 OD0009 y onl ฺA S ru 28-JUN-2005 Pe c erte31-JUL-2004 SC0002 SC0005 SC0007 ib C FedEx and 14-AUG-2006 SC0004 FedEx 21-SEP-2006 SC0003 DHL 28-OCT-2007 SC0001 CN0007 DHL 11-AUG-2007 SC0006 CN0008 DHL 18-SEP-2009 SC0008 CN0009 USPS 25-NOV-2009 SC0009 CN0005 Copyright © 2014.Page 35 .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. All rights reserved. Additional Practices and Solutions Chapter 12 .

Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. and the details of the order placed by the customer. Oracle and/or its affiliates. o.customer_id = o.customer_name. Customer Address.shopping_cart_id FROM customer c JOIN order_details o ON c. ฺ e us ฺ ฺC y onl CREATE VIEW customer_details AS SELECT c. c.customer_id.shipping_type. All rights reserved. o. r e niv U e l ac Or Copyright © 2014.customer_id.Page 36 . ฺA S ru e P c e t er ib C d n a sity SELECT * FROM customer_details ORDER BY customer_id.order_id.street_address. Additional Practices and Solutions Chapter 12 . Create a view named CUSTOMER_DETAILS to show the Customer Name.date_of_purchase. Oracle and/or its affiliatesฺ i. o. Order the results by Customer ID. PURCHASE_HISTORY Customer _ID Order _ID CN0001 OD0001 CN0003 OD0002 CN0004 OD0005 CN0009 OD0007 6. o. o.

shopping_cart_id. Make changes to the data in the tables.customer_id. make an entry in the AUTHOR table. Be sure to include the customer name. ฺ e us ฺ ฺC b. All rights reserved.'150'.book_id.'PN0005'). Unauthorized reproduction or distribution prohibitedฺ Copyright 2012. niv U le c a Or 8. Save the commands that generate the report in a script file named lab_apcs_8. book_id. book ID. Oracle and/or its affiliates. Note: Your results may be different. price.7. c. Add a new book detail.'12'). Oracle and/or its affiliatesฺ a. SELECT c. author_id.quantity) y sit r VALUES ('SC0010'. Copyright © 2014. n a Shopping_cart_date. Create a report that contains each customer’s history of purchasing books. publisher_id) VALUES ('BN0013'.TO_DATE('12-JUN-2006'.'AN0009'.o. customer ID.customer_id JOIN shopping_cart s ON o.'BN0013'. Verify if the author detail for the book is available in the AUTHOR table.sql. Additional Practices and Solutions Chapter 12 . If not.customer_id=c.shopping_cart_id=s. book_name. s. price.Page 37 .customer_name CUSTOMER.'Two States'.'200'. INSERT INTO books(book_id. and shopping cart ID. s. date of purchase.date_of_purchase FROM customer c JOIN order_details o ON o.shopping_cart_id.'DD-MONe YYYY'). y onl ฺA S ru e P c e t er Enter a shopping cart detail for the book details that you just entered in 7(a). ib C d INSERT INTO shopping_cart(shopping_cart_id.

Oracle and/or its affiliatesฺ ฺ e us ฺ ฺC ฺA S ru e P c e t er ib C d n a sity r e niv U e l ac Or Copyright © 2014. Oracle and/or its affiliates. Additional Practices and Solutions Chapter 12 . All rights reserved.Page 38 y onl .Unauthorized reproduction or distribution prohibitedฺ Copyright 2012.