You are on page 1of 254

Volume II • Student Guide

D64258GC10
Edition 1.0
January 2010
D65028

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Oracle Database: SQL
Fundamentals I

Authors

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

Salome Clement
Brian Pottle
Puja Singh

Disclaimer

Anjulaponni Azhagulekshmi
Clair Bennett
Zarko Cesljas
Yanti Chang
Gerlinde Frenzen
Steve Friedberg
Joel Goodman
Nancy Greenberg
Pedro Neves
Manish Pawar
Surya Rekha
Helen Robertson
Lauran Serhal
Hilda Simon
Tulika Srivastava

Editor

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 is a registered trademark of Oracle Corporation and/or its affiliates. Other
names may be trademarks of their respective owners.

Amitha Narayan

Graphic Designer
Rajiv Chandrabhanu

Publisher
Jobi Varghese

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Technical Contributors
and Reviewers

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.

I

Introduction
Lesson Objectives I-2
Lesson Agenda I-3
Course Objectives I-4
Course Agenda I-5
Appendixes Used in the Course I-7
Lesson Agenda I-8
Oracle Database 11g: Focus Areas I-9
Oracle Database 11g I-10
Oracle Fusion Middleware I-12
Oracle Enterprise Manager Grid Control I-13
Oracle BI Publisher I-14
Lesson Agenda I-15
Relational and Object Relational Database Management Systems I-16
Data Storage on Different Media I-17
Relational Database Concept I-18
Definition of a Relational Database I-19
Data Models I-20
Entity Relationship Model I-21
Entity Relationship Modeling Conventions I-23
Relating Multiple Tables I-25
Relational Database Terminology I-27
Lesson Agenda I-29
Using SQL to Query Your Database I-30
SQL Statements I-31
Development Environments for SQL I-32
Lesson Agenda I-33
Human Resources (HR) Schema I-34
Tables Used in the Course I-35
Lesson Agenda I-36
Oracle Database Documentation I-37
Additional Resources I-38
Summary I-39
Practice I: Overview I-40

iii
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Contents

1

Retrieving Data Using the SQL SELECT Statement

Basic SELECT Statement 1-5
Selecting All Columns 1-6
Selecting Specific Columns 1-7
Writing SQL Statements 1-8
Column Heading Defaults 1-9
Lesson Agenda 1-10
Arithmetic Expressions 1-11
Using Arithmetic Operators 1-12
Operator Precedence 1-13
Defining a Null Value 1-14
Null Values in Arithmetic Expressions 1-15
Lesson Agenda 1-16
Defining a Column Alias 1-17
Using Column Aliases 1-18
Lesson Agenda 1-19
Concatenation Operator 1-20
Literal Character Strings 1-21
Using Literal Character Strings 1-22
Alternative Quote (q) Operator 1-23
Duplicate Rows 1-24
Lesson Agenda 1-25
Displaying the Table Structure 1-26
Using the DESCRIBE Command 1-27
Quiz 1-28
Summary 1-29
Practice 1: Overview 1-30
2

Restricting and Sorting Data
Objectives 2-2
Lesson Agenda 2-3
Limiting Rows Using a Selection 2-4
Limiting the Rows That Are Selected 2-5
Using the WHERE Clause 2-6
Character Strings and Dates 2-7
Comparison Operators 2-8
Using Comparison Operators 2-9

iv
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Objectives 1-2
Lesson Agenda 1-3
Capabilities of SQL SELECT Statements 1-4

Range Conditions Using the BETWEEN Operator 2-10
Membership Condition Using the IN Operator 2-11
Pattern Matching Using the LIKE Operator 2-12
Combining Wildcard Characters 2-13
Using the NULL Conditions 2-14
Defining Conditions Using the Logical Operators 2-15
Using the AND Operator 2-16
Using the NOT Operator 2-18
Lesson Agenda 2-19
Rules of Precedence 2-20
Lesson Agenda 2-22
Using the ORDER BY Clause 2-23
Sorting 2-24
Lesson Agenda 2-26
Substitution Variables 2-27
Using the Single-Ampersand Substitution Variable 2-29
Character and Date Values with Substitution Variables 2-31
Specifying Column Names, Expressions, and Text 2-32
Using the Double-Ampersand Substitution Variable 2-33
Lesson Agenda 2-34
Using the DEFINE Command 2-35
Using the VERIFY Command 2-36
Quiz 2-37
Summary 2-38
Practice 2: Overview 2-39
3

Using Single-Row Functions to Customize Output
Objectives 3-2
Lesson Agenda 3-3
SQL Functions 3-4
Two Types of SQL Functions 3-5
Single-Row Functions 3-6
Lesson Agenda 3-8
Character Functions 3-9
Case-Conversion Functions 3-11
Using Case-Conversion Functions 3-12
Character-Manipulation Functions 3-13
Using the Character-Manipulation Functions 3-14
Lesson Agenda 3-15

v
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Using the OR Operator 2-17

Number Functions 3-16 Using the ROUND Function 3-17 Using the TRUNC Function 3-18 Using the SYSDATE Function 3-24 Arithmetic with Dates 3-25 Using Arithmetic Operators with Dates 3-26 Lesson Agenda 3-27 Date-Manipulation Functions 3-28 Using Date Functions 3-29 Using ROUND and TRUNC Functions with Dates 3-30 Quiz 3-31 Summary 3-32 Practice 3: Overview 3-33 4 Using Conversion Functions and Conditional Expressions Objectives 4-2 Lesson Agenda 4-3 Conversion Functions 4-4 Implicit Data Type Conversion 4-5 Explicit Data Type Conversion 4-7 Lesson Agenda 4-10 Using the TO_CHAR Function with Dates 4-11 Elements of the Date Format Model 4-12 Using the TO_CHAR Function with Dates 4-16 Using the TO_CHAR Function with Numbers 4-17 Using the TO_NUMBER and TO_DATE Functions 4-20 Using the TO_CHAR and TO_DATE Function with the RR Date Format 4-22 Lesson Agenda 4-23 Nesting Functions 4-24 Nesting Functions: Example 1 4-25 Nesting Functions: Example 2 4-26 Lesson Agenda 4-27 General Functions 4-28 NVL Function 4-29 Using the NVL Function 4-30 Using the NVL2 Function 4-31 vi THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Using the MOD Function 3-19 Lesson Agenda 3-20 Working with Dates 3-21 RR Date Format 3-22 .

Using the NULLIF Function 4-32 Using the COALESCE Function 4-33 Lesson Agenda 4-36 Conditional Expressions 4-37 CASE Expression 4-38 Using the CASE Expression 4-39 Using the DECODE Function 4-41 Quiz 4-43 Summary 4-44 Practice 4: Overview 4-45 5 Reporting Aggregated Data Using the Group Functions Objectives 5-2 Lesson Agenda 5-3 What Are Group Functions? 5-4 Types of Group Functions 5-5 Group Functions: Syntax 5-6 Using the AVG and SUM Functions 5-7 Using the MIN and MAX Functions 5-8 Using the COUNT Function 5-9 Using the DISTINCT Keyword 5-10 Group Functions and Null Values 5-11 Lesson Agenda 5-12 Creating Groups of Data 5-13 Creating Groups of Data: GROUP BY Clause Syntax 5-14 Using the GROUP BY Clause 5-15 Grouping by More Than One Column 5-17 Using the GROUP BY Clause on Multiple Columns 5-18 Illegal Queries Using Group Functions 5-19 Restricting Group Results 5-21 Restricting Group Results with the HAVING Clause 5-22 Using the HAVING Clause 5-23 Lesson Agenda 5-25 Nesting Group Functions 5-26 Quiz 5-27 Summary 5-28 Practice 5: Overview 5-29 vii THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only DECODE Function 4-40 .

Displaying Data from Multiple Tables Using Joins Objectives 6-2 Lesson Agenda 6-3 Obtaining Data from Multiple Tables 6-4 Types of Joins 6-5 Joining Tables Using SQL:1999 Syntax 6-6 Qualifying Ambiguous Column Names 6-7 Lesson Agenda 6-8 Creating Natural Joins 6-9 Retrieving Records with Natural Joins 6-10 Creating Joins with the USING Clause 6-11 Joining Column Names 6-12 Retrieving Records with the USING Clause 6-13 Using Table Aliases with the USING Clause 6-14 Creating Joins with the ON Clause 6-15 Retrieving Records with the ON Clause 6-16 Creating Three-Way Joins with the ON Clause 6-17 Applying Additional Conditions to a Join 6-18 Lesson Agenda 6-19 Joining a Table to Itself 6-20 Self-Joins Using the ON Clause 6-21 Lesson Agenda 6-22 Nonequijoins 6-23 Retrieving Records with Nonequijoins 6-24 Lesson Agenda 6-25 Returning Records with No Direct Match Using OUTER Joins 6-26 INNER Versus OUTER Joins 6-27 LEFT OUTER JOIN 6-28 RIGHT OUTER JOIN 6-29 FULL OUTER JOIN 6-30 Lesson Agenda 6-31 Cartesian Products 6-32 Generating a Cartesian Product 6-33 Creating Cross Joins 6-34 Quiz 6-35 Summary 6-36 Practice 6: Overview 6-37 viii THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 6 .

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 7 .Using Subqueries to Solve Queries Objectives 7-2 Lesson Agenda 7-3 Using a Subquery to Solve a Problem 7-4 Subquery Syntax 7-5 Using a Subquery 7-6 Guidelines for Using Subqueries 7-7 Types of Subqueries 7-8 Lesson Agenda 7-9 Single-Row Subqueries 7-10 Executing Single-Row Subqueries 7-11 Using Group Functions in a Subquery 7-12 HAVING Clause with Subqueries 7-13 What Is Wrong with This Statement? 7-14 No Rows Returned by the Inner Query 7-15 Lesson Agenda 7-16 Multiple-Row Subqueries 7-17 Using the ANY Operator in Multiple-Row Subqueries 7-18 Using the ALL Operator in Multiple-Row Subqueries 7-19 Using the EXISTS Operator 7-20 Lesson Agenda 7-21 Null Values in a Subquery 7-22 Quiz 7-24 Summary 7-25 Practice 7: Overview 7-26 8 Using the Set Operators Objectives 8-2 Lesson Agenda 8-3 Set Operators 8-4 Set Operator Guidelines 8-5 Oracle Server and Set Operators 8-6 Lesson Agenda 8-7 Tables Used in This Lesson 8-8 Lesson Agenda 8-12 UNION Operator 8-13 Using the UNION Operator 8-14 UNION ALL Operator 8-16 Using the UNION ALL Operator 8-17 Lesson Agenda 8-18 ix THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

INTERSECT Operator 8-19 Using the INTERSECT Operator 8-20 Lesson Agenda 8-21 MINUS Operator 8-22 Matching the SELECT Statement: Example 8-26 Lesson Agenda 8-27 Using the ORDER BY Clause in Set Operations 8-28 Quiz 8-29 Summary 8-30 Practice 8: Overview 8-31 9 Manipulating Data Objectives 9-2 Lesson Agenda 9-3 Data Manipulation Language 9-4 Adding a New Row to a Table 9-5 INSERT Statement Syntax 9-6 Inserting New Rows 9-7 Inserting Rows with Null Values 9-8 Inserting Special Values 9-9 Inserting Specific Date and Time Values 9-10 Creating a Script 9-11 Copying Rows from Another Table 9-12 Lesson Agenda 9-13 Changing Data in a Table 9-14 UPDATE Statement Syntax 9-15 Updating Rows in a Table 9-16 Updating Two Columns with a Subquery 9-17 Updating Rows Based on Another Table 9-18 Lesson Agenda 9-19 Removing a Row from a Table 9-20 DELETE Statement 9-21 Deleting Rows from a Table 9-22 Deleting Rows Based on Another Table 9-23 TRUNCATE Statement 9-24 Lesson Agenda 9-25 Database Transactions 9-26 x THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Using the MINUS Operator 8-23 Lesson Agenda 8-24 Matching the SELECT Statements 8-25 .

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only State of the Data After COMMIT 9-34 Committing Data 9-35 State of the Data After ROLLBACK 9-36 .Database Transactions: Start and End 9-27 Advantages of COMMIT and ROLLBACK Statements 9-28 Explicit Transaction Control Statements 9-29 Rolling Back Changes to a Marker 9-30 Implicit Transaction Processing 9-31 State of the Data Before COMMIT or ROLLBACK 9-33 State of the Data After ROLLBACK: Example 9-37 Statement-Level Rollback 9-38 Lesson Agenda 9-39 Read Consistency 9-40 Implementing Read Consistency 9-41 Lesson Agenda 9-42 FOR UPDATE Clause in a SELECT Statement 9-43 FOR UPDATE Clause: Examples 9-44 Quiz 9-46 Summary 9-47 Practice 9: Overview 9-48 10 Using DDL Statements to Create and Manage Tables Objectives 10-2 Lesson Agenda 10-3 Database Objects 10-4 Naming Rules 10-5 Lesson Agenda 10-6 CREATE TABLE Statement 10-7 Referencing Another User’s Tables 10-8 DEFAULT Option 10-9 Creating Tables 10-10 Lesson Agenda 10-11 Data Types 10-12 Datetime Data Types 10-14 Lesson Agenda 10-15 Including Constraints 10-16 Constraint Guidelines 10-17 Defining Constraints 10-18 NOT NULL Constraint 10-20 UNIQUE Constraint 10-21 xi THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

PRIMARY KEY Constraint 10-23 FOREIGN KEY Constraint 10-24 FOREIGN KEY Constraint: Keywords 10-26 CREATE TABLE: Example 10-28 Violating Constraints 10-29 Lesson Agenda 10-31 Creating a Table Using a Subquery 10-32 Lesson Agenda 10-34 ALTER TABLE Statement 10-35 Read-Only Tables 10-36 Lesson Agenda 10-37 Dropping a Table 10-38 Quiz 10-39 Summary 10-40 Practice 10: Overview 10-41 11 Creating Other Schema Objects Objectives 11-2 Lesson Agenda 11-3 Database Objects 11-4 What Is a View? 11-5 Advantages of Views 11-6 Simple Views and Complex Views 11-7 Creating a View 11-8 Retrieving Data from a View 11-11 Modifying a View 11-12 Creating a Complex View 11-13 Rules for Performing DML Operations on a View 11-14 Using the WITH CHECK OPTION Clause 11-17 Denying DML Operations 11-18 Removing a View 11-20 Practice 11: Overview of Part 1 11-21 Lesson Agenda 11-22 Sequences 11-23 CREATE SEQUENCE Statement: Syntax 11-25 Creating a Sequence 11-26 NEXTVAL and CURRVAL Pseudocolumns 11-27 Using a Sequence 11-29 Caching Sequence Values 11-30 xii THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only CHECK Constraint 10-27 .

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Modifying a Sequence 11-31 Guidelines for Modifying a Sequence 11-32 Lesson Agenda 11-33 Indexes 11-34 How Are Indexes Created? 11-36 Creating an Index 11-37 Index Creation Guidelines 11-38 Removing an Index 11-39 Lesson Agenda 11-40 Synonyms 11-41 Creating a Synonym for an Object 11-42 Creating and Removing Synonyms 11-43 Quiz 11-44 Summary 11-45 Practice 11: Overview of Part 2 11-46 .5 Interface C-5 Creating a Database Connection C-7 Browsing Database Objects C-10 Displaying the Table Structure C-11 Browsing Files C-12 Creating a Schema Object C-13 Creating a New Table: Example C-14 Using the SQL Worksheet C-15 Executing SQL Statements C-18 Saving SQL Scripts C-19 Executing Saved Script Files: Method 1 C-20 Executing Saved Script Files: Method 2 C-21 Formatting the SQL Code C-22 Using Snippets C-23 Using Snippets: Example C-24 xiii THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Appendix A: Practices and Solutions Appendix AP: Additional Practices and Solutions Appendix B: Table Descriptions Appendix C: Using SQL Developer Objectives C-2 What Is Oracle SQL Developer? C-3 Specifications of SQL Developer C-4 SQL Developer 1.

n. and APPEND D-11 Using the CHANGE Command D-12 SQL*Plus File Commands D-13 Using the SAVE. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Debugging Procedures and Functions C-25 Database Reporting C-26 Creating a User-Defined Report C-27 Search Engines and External Tools C-28 Setting Preferences C-29 Resetting the SQL Developer Layout C-30 Summary C-31 . START Commands D-14 SERVEROUTPUT Command D-15 Using the SQL*Plus SPOOL Command D-16 Using the AUTOTRACE Command D-17 Summary D-18 Appendix E: Using JDeveloper Objectives E-2 Oracle JDeveloper E-3 Database Navigator E-4 Creating Connection E-5 Browsing Database Objects E-6 Executing SQL Statements E-7 Creating Program Units E-8 Compiling E-9 Running a Program Unit E-10 Dropping a Program Unit E-11 Structure Window E-12 Editor Window E-13 Application Navigator E-14 Deploying Java Stored Procedures E-15 xiv THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Appendix D: Using SQL*Plus Objectives D-2 SQL and SQL*Plus Interaction D-3 SQL Statements Versus SQL*Plus Commands D-4 Overview of SQL*Plus D-5 Logging In to SQL*Plus D-6 Displaying the Table Structure D-7 SQL*Plus Editing Commands D-9 Using LIST.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Publishing Java to PL/SQL E-16 How Can I Learn More About JDeveloper 11g? E-17 Summary E-18 .Appendix F: Oracle Join Syntax Objectives F-2 Obtaining Data from Multiple Tables F-3 Cartesian Products F-4 Generating a Cartesian Product F-5 Types of Oracle-Proprietary Joins F-6 Joining Tables Using Oracle Syntax F-7 Qualifying Ambiguous Column Names F-8 Equijoins F-9 Retrieving Records with Equijoins F-10 Retrieving Records with Equijoins: Example F-11 Additional Search Conditions Using the AND Operator F-12 Joining More than Two Tables F-13 Nonequijoins F-14 Retrieving Records with Nonequijoins F-15 Returning Records with No Direct Match with Outer Joins F-16 Outer Joins: Syntax F-17 Using Outer Joins F-18 Outer Join: Another Example F-19 Joining a Table to Itself F-20 Self-Join: Example F-21 Summary F-22 Practice F: Overview F-23 Index xv THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

Oracle University and TechnoLogica use only THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .

Oracle University and TechnoLogica use only Appendix A Practices and Solutions THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .

...................................................... 88 Oracle Database: SQL Fundamentals I A ............. 3 Practice I-1: Introduction ............ 32 Practices for Lesson 4 ................................................................................................................................... 52 Practices for Lesson 7 ....................................................................... 54 Practice 7-1: Using Subqueries to Solve Queries ....................................... 12 Practice Solutions 1-1: Retrieving Data Using the SQL SELECT Statement ..................................................................................................... 35 Practice 4-1: Using Conversion Functions and Conditional Expressions ...................................................................................................... 65 Practice Solutions 9-1: Manipulating Data .................................................................................................... 27 Practice 3-1: Using Single-Row Functions to Customize Output ....................................................................................................................... 64 Practice 9-1: Manipulating Data .......................................................................................................... 74 Practice Solutions 10-1: Using DDL Statements to Create and Manage Tables ............... 79 Practice 11-1: Creating Other Schema Objects .................................................................................. 85 Practice Solutions F-1: Oracle Join Syntax ................................................................................................ 84 Practice F-1: Oracle Join Syntax......................... 69 Practices for Lesson 10 ............................................................................................ 41 Practice 5-1: Reporting Aggregated Data Using the Group Functions......................................................... 60 Practice Solutions 8-1: Using the Set Operators .. 5 Practices for Lesson 1 .................................... 16 Practices for Lesson 2 ................................................................. 48 Practice 6-1: Displaying Data from Multiple Tables Using Joins ............................................................................................................................................................................................................................................... 57 Practices for Lesson 8 .................................................................................. 76 Practices for Lesson 11 .............................. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Table of Contents ........... 42 Practice Solutions 5-1: Reporting Aggregated Data Using the Group Functions ......................................................................................... 59 Practice 8-1: Using the Set Operators ........................................................................................ 36 Practice Solutions 4-1: Using Conversion Functions and Conditional Expressions ......................... 49 Practice Solutions 6-1: Displaying Data from Multiple Tables Using Joins .............................................Practices for Lesson I ........ 4 Practice Solutions I-1: Introduction ...................................................... 82 Practices for Appendix F ............................... 62 Practices for Lesson 9 ........................................................... 24 Practices for Lesson 3 ..........................2 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.................................................................. 20 Practice Solutions 2-1: Restricting and Sorting Data ........... 45 Practices for Lesson 6 . 28 Practice Solutions 3-1: Using Single-Row Functions to Customize Output ............... 73 Practice 10-1: Using DDL Statements to Create and Manage Tables ................... 11 Practice 1-1: Retrieving Data Using the SQL SELECT Statement ....................................... 19 Practice 2-1: Restricting and Sorting Data. 80 Practice Solutions 11-1: Creating Other Schema Objects ................................................................... 39 Practices for Lesson 5 ........................................................................................................................................................................................................................ 55 Practice Solutions 7-1: Using Subqueries to Solve Queries .....................................

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only If you are asked to save any lab files.Practices for Lesson I In this practice. • Use Oracle SQL Developer to examine data objects in the ora1 account. there may be exercises that are prefaced with the phrases “If you have time” or “If you want an extra challenge. . the sequence of rows retrieved from the database may differ from the screenshots shown. save them in this location. you can also use SQL*Plus that is available in this course. 2) For any query. ask your instructor. If you have any questions at any time. You can experiment with saving and running command files. Note 1) All written practices use Oracle SQL Developer as the development environment. The ora1 account contains the HR schema tables. Oracle Database: SQL Fundamentals I A . you perform the following: • Start Oracle SQL Developer and create a new connection to the ora1 account.3 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Perform the practices slowly and precisely. Note the following location for the lab files: \home\oracle\labs\sql1\labs In any practice.” Work on these exercises only if you have completed all other exercises within the allocated time and would like a further challenge to your skills. Although it is recommended that you use Oracle SQL Developer.

5) If the status is Success. Testing and Connecting Using the Oracle SQL Developer Database Connection 4) Test the new connection. 3) Create a database connection using the following information: a) Connection Name: myconnection b) Username: ora1 c) Password: ora1 d) Hostname: localhost e) Port: 1521 f) SID: ORCL Ensure that you select the Save Password check box. connect to the database using this new connection. Select New Connection from the menu. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Creating a New Oracle SQL Developer Database Connection . view the objects available to you in the Tables node. The New/Select Database Connection dialog box appears. 2) To create a new database connection. Verify that the following tables are present: COUNTRIES DEPARTMENTS EMPLOYEES JOB_GRADES JOB_HISTORY JOBS LOCATIONS REGIONS 7) Browse the structure of the EMPLOYEES table. right-click Connections. 8) View the data of the DEPARTMENTS table. Oracle Database: SQL Fundamentals I A . Practices are intended to cover most of the topics that are presented in the corresponding lesson. The solutions (if you require them) can be found at the end of this practice. Browsing the Tables in the Connections Navigator 6) In the Connections Navigator. in the Connections Navigator.4 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Starting Oracle SQL Developer 1) Start Oracle SQL Developer using the SQL Developer desktop icon.Practice I-1: Introduction This is the first of many practices in this course.

. in the Connections Navigator. a) Double-click the SQL Developer desktop icon. Oracle Database: SQL Fundamentals I A .5 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only The SQL Developer Interface appears. Creating a New Oracle SQL Developer Database Connection 2) To create a new database connection.Practice Solutions I-1: Introduction Starting Oracle SQL Developer 1) Start Oracle SQL Developer using the SQL Developer desktop icon. right-click Connections and select New Connection from the menu.

6 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practice Solutions I-1: Introduction (continued) 3) Create a database connection using the following information: a) Connection Name: myconnection b) Username: ora1 c) Password: ora1 d) Hostname: localhost e) Port: 1521 f) SID: ORCL Ensure that you select the Save Password check box. Oracle Database: SQL Fundamentals I A . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only The New / Select Database Connection dialog box appears. .

Oracle Database: SQL Fundamentals I A .7 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 5) If the status is Success.Testing and Connecting Using the Oracle SQL Developer Database Connection 4) Test the new connection. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Practice Solutions I-1: Introduction (continued) . connect to the database using this new connection.

When you create a connection. view the objects available to you in the Tables node. a SQL Worksheet for that connection opens automatically. Verify that the following tables are present: COUNTRIES DEPARTMENTS EMPLOYEES JOB_GRADES JOB_HISTORY JOBS LOCATIONS REGIONS Oracle Database: SQL Fundamentals I A .8 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Browsing the Tables in the Connections Navigator 6) In the Connections Navigator. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Practice Solutions I-1: Introduction (continued) .

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Practice Solutions I-1: Introduction (continued) .9 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 8) View the data of the DEPARTMENTS table.7) Browse the structure of the EMPLOYEES table. Oracle Database: SQL Fundamentals I A .

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Oracle University and TechnoLogica use only Practice Solutions I-1: Introduction (continued) Oracle Database: SQL Fundamentals I A .10 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

The queries cover most of the SELECT clauses and operations that you learned in this lesson. Oracle Database: SQL Fundamentals I A .11 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you write simple SELECT queries. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Practices for Lesson 1 Oracle University and TechnoLogica use only In this practice.

For DML and DDL statements. • To run the query. click the Execute Statement icon in the SQL Worksheet. Oracle Database: SQL Fundamentals I A . You have been hired as a SQL programmer for Acme Corporation. select Save As to save your SQL statement as a lab_<lessonno>_<stepno>. True/False 3) There are four coding errors in the following statement. Part 2 Note the following points before you begin with the practices: • Save all your lab files at the following location: /home/oracle/labs/sql1/labs • Enter your SQL statements in a SQL Worksheet. make sure that you use Save As to save it with a different file name. • After you have executed the query. Open a new worksheet.12 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. salary AS Sal FROM employees. last_name ANNUAL SALARY employees. use the Run Script icon or press [F5]. To save a script in SQL Developer. make sure that the required SQL worksheet is active and then from the File menu. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only True/False . Can you identify them? SELECT sal x 12 FROM employee_id. make sure that you do not enter your next query in the same worksheet. 2) The following SELECT statement executes successfully: SELECT * FROM job_grades. Your first task is to create some reports based on data from the Human Resources tables. When you are modifying an existing script. Alternatively.sql script. job_id. you can press [F9].Practice 1-1: Retrieving Data Using the SQL SELECT Statement Part 1 Test your knowledge: 1) The following SELECT statement executes successfully: SELECT last_name.

Open a new worksheet. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 4) Your first task is to determine the structure of the DEPARTMENTS table and its contents. The HR department wants a query to display the last name. job ID.Practice 1-1: Retrieving Data Using the SQL SELECT Statement (continued) 5) Determine the structure of the EMPLOYEES table.sql so that you can dispatch this file to the HR department. with the employee ID appearing first. make sure that you do not enter your next query in the same worksheet. . Provide an alias STARTDATE for the HIRE_DATE column. Save your SQL statement to a file named lab_01_05. Oracle Database: SQL Fundamentals I A .sql file to ensure that it runs correctly. and employee ID for each employee.13 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 6) Test your query in the lab_01_05. Note: After you have executed the query. hire date.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only … .Practice 1-1: Retrieving Data Using the SQL SELECT Statement (continued) 7) The HR department wants a query to display all unique job IDs from the EMPLOYEES table.sql to a new SQL Worksheet. Job. Name the column headings Emp #. and Hire Date. complete the following exercises: 8) The HR department wants more descriptive column headings for its report on employees. Copy the statement from lab_01_05. Part 3 If you have time.14 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Employee. Then run the query again. respectively. … Oracle Database: SQL Fundamentals I A .

. create a query to display all the data from that table. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 9) The HR department has requested a report of all employees and their job IDs. Name the column title THE_OUTPUT.Practice 1-1: Retrieving Data Using the SQL SELECT Statement (continued) … If you want an extra challenge. complete the following exercise: 10) To familiarize yourself with the data in the EMPLOYEES table. … Oracle Database: SQL Fundamentals I A .15 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Display the last name concatenated with the job ID (separated by a comma and space) and name the column Employee and Title. Separate each column output by a comma.

. Part 2 You have been hired as a SQL programmer for Acme Corporation. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT last_name.  A comma is missing after the LAST_NAME column.Practice Solutions 1-1: Retrieving Data Using the SQL SELECT Statement Part 1 Test your knowledge: 1) The following SELECT statement executes successfully: True/False 2) The following SELECT statement executes successfully: SELECT * FROM job_grades. not x.  The EMPLOYEES table does not contain a column called sal. The alias should read ANNUAL_SALARY or should be enclosed within double quotation marks.16 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.  The ANNUAL SALARY alias cannot include spaces. To determine the DEPARTMENTS table structure: DESCRIBE departments Oracle Database: SQL Fundamentals I A . job_id. 4) Your first task is to determine the structure of the DEPARTMENTS table and its contents. a. Can you identify them? SELECT sal x 12 FROM employee_id.  The multiplication operator is *. True/False 3) There are four coding errors in the following statement. as shown in line 2. Your first task is to create some reports based on data from the Human Resources tables. The column is called SALARY. salary AS Sal FROM employees. last_name ANNUAL SALARY employees.

SELECT last_name||'. hire_date StartDate FROM employees. Job. 5) Determine the structure of the EMPLOYEES table. and employee ID for each employee. hire_date "Hire Date" FROM employees. Save your SQL statement to a file named lab_01_05. job ID. last_name. Part 3 If you have time. job_id. Provide an alias STARTDATE for the HIRE_DATE column. 7) The HR department wants a query to display all unique job IDs from the EMPLOYEES table. Oracle Database: SQL Fundamentals I A . To view the data contained in the DEPARTMENTS table: SELECT * FROM departments. SELECT employee_id. '||job_id "Employee and Title" FROM employees. respectively. Employee. SELECT employee_id "Emp #". Display the last name concatenated with the job ID (separated by a comma and space) and name the column Employee and Title. 9) The HR department has requested a report of all employees and their job IDs. hire date. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only DESCRIBE employees . 6) Test your query in the lab_01_05.sql to a new SQL Worksheet. hire_date StartDate FROM employees. complete the following exercises: 8) The HR department wants more descriptive column headings for its report on employees. last_name.Practice Solutions 1-1: Retrieving Data Using the SQL SELECT Statement (continued) b. SELECT employee_id.sql so that you can dispatch this file to the HR department. Name the column headings Emp #.17 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. The HR department wants a query to display the last name. last_name "Employee". and Hire Date.sql file to ensure that it runs correctly. SELECT DISTINCT job_id FROM employees. Copy the statement from lab_01_05. Then run the query again. job_id. with the employee ID appearing first. job_id "Job".

' || phone_number || '.Practice Solutions 1-1: Retrieving Data Using the SQL SELECT Statement (continued) If you want an extra challenge. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 10) To familiarize yourself with the data in the EMPLOYEES table.' || salary || '. Oracle Database: SQL Fundamentals I A .' || commission_pct || '.' || email || '.' || first_name || '.' || last_name || '.'|| job_id || '.' || hire_date || '.18 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.' || department_id THE_OUTPUT FROM employees. complete the following exercise: SELECT employee_id || '. . Name the column title THE_OUTPUT. create a query to display all the data from that table. Separate each column output by a comma.' || manager_id || '.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .19 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Oracle Database: SQL Fundamentals I A . You make the SQL statements more reusable and generic by including the ampersand substitution. including statements that use the WHERE clause and the ORDER BY clause. you build more reports.Practices for Lesson 2 Oracle University and TechnoLogica use only In this practice.

Save your SQL statement as lab_02_03. 2) Open a new SQL Worksheet. Run your query. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 1) Because of budget issues. Run the query. Modify lab_02_01. the HR department needs a report that displays the last name and salary of employees who earn more than $12. Oracle Database: SQL Fundamentals I A .20 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. .Practice 2-1: Restricting and Sorting Data The HR department needs your assistance in creating some queries.000. and hire date for employees with the last names of Matos and Taylor. 3) The HR department needs to find high-salary and low-salary employees. Save your SQL statement as a file named lab_02_01. Create a report that displays the last name and department number for employee number 176. 4) Create a report to display the last name.sql. Order the query in ascending order by the hire date. job ID.000 to $12.sql to display the last name and salary for any employee whose salary is not in the range of $5.000.sql.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 5) Display the last name and department ID of all employees in departments 20 or 50 in ascending alphabetical order by name.21 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Use the column’s numeric position in the ORDER BY clause. Label the columns Employee and Monthly Salary. 9) Create a report to display the last name.000 and $12. 7) The HR department needs a report that displays the last name and hire date for all employees who were hired in 1994. Oracle Database: SQL Fundamentals I A .sql.sql to display the last name and salary of employees who earn between $5. Run the statement in lab_02_06. . Save lab_02_03.000.sql again. and are in department 20 or 50. respectively.sql as lab_02_06.Practice 2-1: Restricting and Sorting Data (continued) 6) Modify lab_02_03. Sort data in descending order of salary and commissions. and commission of all employees who earn commissions. salary. 8) Create a report to display the last name and job title of all employees who do not have a manager.

The HR department wants the ability to sort the report on a selected column.22 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. sorted by salary: manager_id = 124. sorted by employee_id: If you have time.sql. sorted by last_name: manager_id = 201. salary. If you enter 12000 when prompted. last name. and department for that manager’s employees. the report displays the following results: .” Oracle Database: SQL Fundamentals I A . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 10) Members of the HR department want to have more flexibility with the queries that you are writing. complete the following exercises: 12) Display all employee last names in which the third letter of the name is “a. Save this query to a file named lab_02_10. 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. Create a query that prompts the user for a manager ID and generates the employee ID. You can test the data with the following values: manager_id = 103.Practice 2-1: Restricting and Sorting Data (continued) 11) The HR department wants to run reports based on a manager.

sql as lab_02_15. and salary for all employees whose jobs are either those of a sales representative or of a stock clerk.sql.500. Rerun the statement in lab_02_15. 14) Display the last name. Oracle Database: SQL Fundamentals I A . 15) Modify lab_02_06. Save lab_02_06. or $7.Practice 2-1: Restricting and Sorting Data (continued) 13) Display the last names of all employees who have both an “a” and an “e” in their last name. complete the following exercises: . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only If you want an extra challenge. $3. and whose salaries are not equal to $2.sql again. salary. job.23 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and commission for all employees whose commission is 20%.000.500.sql to display the last name.

SELECT FROM WHERE ORDER BY last_name.sql again. and hire date for employees with the last names of Matos and Taylor. 50). SELECT FROM WHERE last_name. salary "Monthly Salary" employees salary BETWEEN 5000 AND 12000 department_id IN (20.000. Create a report that displays the last name and department number for employee number 176. Order the query in ascending order by hire date.sql.24 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. SELECT FROM WHERE ORDER BY last_name. Save your SQL statement as a file named lab_02_01. respectively. Label the columns Employee and Monthly Salary. 1) Because of budget issues.sql as lab_02_06.Practice Solutions 2-1: Restricting and Sorting Data The HR department needs your assistance in creating some queries. 3) The HR department needs to find high-salary and low-salary employees. . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 2) Open a new SQL Worksheet.sql to display the last name and salary for all employees whose salary is not in the range $5. Oracle Database: SQL Fundamentals I A .sql.sql. Modify lab_02_01. 5) Display the last name and department ID of all employees in departments 20 or 50 in ascending alphabetical order by name. job_id. 4) Create a report to display the last name. department_id employees department_id IN (20.000. the HR department needs a report that displays the last name and salary of employees earning more than $12. Run your query. and are in department 20 or 50. department_id employees employee_id = 176.000 through $12. SELECT FROM WHERE last_name. SELECT FROM WHERE last_name.000. salary employees salary NOT BETWEEN 5000 AND 12000.sql to list the last name and salary of employees who earn between $5. Run the statement in lab_02_06. 'Taylor') hire_date. 50) last_name ASC. SELECT FROM WHERE AND last_name "Employee". Save lab_02_03. salary employees salary > 12000. hire_date employees last_name IN ('Matos'. job ID.000 and $12. Save your SQL statement as lab_02_03. 6) Modify lab_02_03.

sorted by employee_id Oracle Database: SQL Fundamentals I A . Create a query that prompts the user for a manager ID and generates the employee ID. salary. 8) Create a report to display the last name and job title of all employees who do not have a manager. SELECT FROM WHERE last_name. and commission for all employees who earn commissions. salary. last name. commission_pct employees commission_pct IS NOT NULL 2 DESC. 9) Create a report to display the last name. You can test the data with the following values: manager _id = 103. sorted by last_name manager_id = 201. sorted by salary manager_id = 124. last_name. Sort data in descending order of salary and commissions. 11) The HR department wants to run reports based on a manager. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT FROM WHERE . SELECT FROM WHERE ORDER BY last_name. Click OK.) Save this query to a file named lab_02_10.sql. Enter 12000 when prompted for a value in a dialog box. SELECT FROM WHERE last_name. The HR department wants the ability to sort the report on a selected column. and department for that manager’s employees.25 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 10) Members of the HR department want to have more flexibility with the queries that you are writing. job_id employees manager_id IS NULL. Use the column’s numeric position in the ORDER BY clause. (You can use the query created in practice exercise 1 and modify it. salary employees salary > &sal_amt. 3 DESC. hire_date employees hire_date LIKE '%94'. 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.Practice Solutions 2-1: Restricting and Sorting Data (continued) 7) The HR department needs a report that displays the last name and hire date for all employees who were hired in 1994. salary.

sql. 13) Display the last names of all employees who have both an “a” and an “e” in their last name. If you want an extra challenge. commission_pct employees commission_pct = . and whose salary is not equal to $2. Save lab_02_06. and commission for all employees whose commission amount is 20%.26 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and salary for all employees whose job is that of a sales representative or a stock clerk. complete the following exercises: 12) Display all employee last names in which the third letter of the name is “a. 7000).20. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT FROM WHERE . salary "Monthly Salary". Rerun the statement in lab_02_15. Oracle Database: SQL Fundamentals I A . salary.” last_name employees last_name LIKE '__a%'.sql again. or $7. salary. last_name. 3500. If you have the time.000. 15) Modify lab_02_06. SELECT FROM WHERE last_name "Employee".500.Practice Solutions 2-1: Restricting and Sorting Data (continued) SELECT employee_id. 'ST_CLERK') salary NOT IN (2500. SELECT FROM WHERE AND last_name. salary employees job_id IN ('SA_REP'. department_id FROM employees WHERE manager_id = &mgr_num ORDER BY &order_col. SELECT FROM WHERE AND last_name employees last_name LIKE '%a%' last_name LIKE '%e%'. $3. job_id.500.sql as lab_02_15.sql to display the last name. complete the following exercises: 14) Display the last name. job.

and date data types.Practices for Lesson 3 Oracle University and TechnoLogica use only This practice provides a variety of exercises using different functions that are available for character. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .27 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Oracle Database: SQL Fundamentals I A . number.

Save your SQL statement in a file named lab_03_02.sql file.28 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. salary. Run the revised query. … 4) Modify your query lab_03_02. the output will be the date for the operating system on which the database resides. Label the column New Salary. Label the column Date. … Oracle Database: SQL Fundamentals I A . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Note: If your database is remotely located in a different time zone.5% (expressed as a whole number) for each employee.Practice 3-1: Using Single-Row Functions to Customize Output 1) Write a query to display the system date.sql. 3) Run your query in the lab_03_02. Label the column Increase. last name. and salary increased by 15.sql.sql to add a column that subtracts the old salary from the new salary. 2) The HR department needs a report to display the employee number. Save the contents of the file as lab_03_04. .

if the user enters “H” (capitalized) when prompted for a letter. display the last name and calculate the number of months between today and the date on which the employee was hired. Label the column as MONTHS_WORKED.29 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 6) The HR department wants to find the duration of employment for each employee.Practice 3-1: Using Single-Row Functions to Customize Output (continued) Rewrite the query so that the user is prompted to enter a letter that the last name starts with. then the output should show all employees whose last name starts with the letter “H. Sort the results by the employees’ last names.” Modify the query such that the case of the entered letter does not affect the output. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 5) 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. . The entered letter must be capitalized before being processed by the SELECT query. For each employee. For example. Note: Because this query depends on the date when it was executed. the values in the MONTHS_WORKED column will differ for you.” “A.” Give each column an appropriate label. Oracle Database: SQL Fundamentals I A . Order your results by the number of months employed.” or “M. Round the number of months up to the closest whole number.

Format the salary to be 15 characters long. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only … . Label the column SALARY. Sort the data in descending order of salary. left-padded with the $ symbol. … Oracle Database: SQL Fundamentals I A .Practice 3-1: Using Single-Row Functions to Customize Output (continued) If you have time. Each asterisk signifies a thousand dollars. … 8) Create a query that displays the first eight characters of the employees’ last names and indicates the amounts of their salaries with asterisks.30 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Label the column EMPLOYEES_AND_THEIR_SALARIES. complete the following exercises: 7) Create a query to display the last name and salary for all employees.

Practice 3-1: Using Single-Row Functions to Customize Output
(continued)
9) Create a query to display the last name and the number of weeks employed for all
employees in department 90. Label the number of weeks column TENURE. Truncate
the number of weeks value to 0 decimal places. Show the records in descending order
of the employee’s tenure.

Oracle University and TechnoLogica use only

Note: The TENURE value will differ as it depends on the date on which you run the
query.

Oracle Database: SQL Fundamentals I A - 31

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Practice Solutions 3-1: Using Single-Row Functions to
Customize Output
1) Write a query to display the system date. Label the column Date.
Note: If your database is remotely located in a different time zone, the output will be
the date for the operating system on which the database resides.
sysdate "Date"
dual;

2) The HR department needs a report to display the employee number, last name, salary,
and salary increased by 15.5% (expressed as a whole number) for each employee.
Label the column New Salary. Save your SQL statement in a file named
lab_03_02.sql.
SELECT
FROM

employee_id, last_name, salary,
ROUND(salary * 1.155, 0) "New Salary"
employees;

3) Run your query in the file lab_03_02.sql.
SELECT
FROM

employee_id, last_name, salary,
ROUND(salary * 1.155, 0) "New Salary"
employees;

4) Modify your query lab_03_02.sql to add a column that subtracts the old salary
from the new salary. Label the column Increase. Save the contents of the file as
lab_03_04.sql. Run the revised query.
SELECT

FROM

employee_id, last_name, salary,
ROUND(salary * 1.155, 0) "New Salary",
ROUND(salary * 1.155, 0) - salary "Increase"
employees;

5) 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,” or “M.” Give each column an appropriate label.
Sort the results by the employees’ last names.
SELECT

INITCAP(last_name) "Name",
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 ;

Rewrite the query so that the user is prompted to enter a letter that starts the last
name. For example, if the user enters H (capitalized) when prompted for a letter, then
the output should show all employees whose last name starts with the letter “H.”

Oracle Database: SQL Fundamentals I A - 32

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

SELECT
FROM

Practice Solutions 3-1: Using Single-Row Functions to
Customize Output (continued)
SELECT

INITCAP(last_name) "Name",
LENGTH(last_name) "Length"
FROM
employees
WHERE
last_name LIKE '&start_letter%'
ORDER BY last_name;

SELECT INITCAP(last_name) "Name",
LENGTH(last_name) "Length"
FROM
employees
WHERE
last_name LIKE UPPER('&start_letter%' )
ORDER BY last_name;

6) The HR department wants to find the duration of employment for each employee. For
each employee, display the last name and calculate the number of months between
today and the date on which the employee was hired. Label the column
MONTHS_WORKED. Order your results by the number of months employed. Round
the number of months up to the closest whole number.
Note: Because this query depends on the date when it was executed, the values in the
MONTHS_WORKED column will differ for you.
SELECT last_name, ROUND(MONTHS_BETWEEN(
SYSDATE, hire_date)) MONTHS_WORKED
FROM
employees
ORDER BY months_worked;

If you have the time, complete the following exercises:
7) Create a query to display the last name and salary for all employees. Format the
salary to be 15 characters long, left-padded with the $ symbol. Label the column
SALARY.
SELECT last_name,
LPAD(salary, 15, '$') SALARY
FROM
employees;

8) Create a query that displays the first eight characters of the employees’ last names
and indicates the amounts of their salaries with asterisks. Each asterisk signifies a
thousand dollars. Sort the data in descending order of salary. Label the column
EMPLOYEES_AND_THEIR_SALARIES.
SELECT rpad(last_name, 8)||' '||
rpad(' ', salary/1000+1, '*')
EMPLOYEES_AND_THEIR_SALARIES
FROM employees
ORDER BY salary DESC;

Oracle Database: SQL Fundamentals I A - 33

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Modify the query such that the case of the entered letter does not affect the output. The
entered letter must be capitalized before being processed by the SELECT query.

Practice Solutions 3-1: Using Single-Row Functions to
Customize Output (continued)
9) Create a query to display the last name and the number of weeks employed for all
employees in department 90. Label the number of weeks column TENURE. Truncate
the number of weeks value to 0 decimal places. Show the records in descending order
of the employee’s tenure.

SELECT last_name, trunc((SYSDATE-hire_date)/7) AS TENURE
FROM
employees
WHERE department_id = 90
ORDER BY TENURE DESC

Oracle Database: SQL Fundamentals I A - 34

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Note: The TENURE value will differ as it depends on the date when you run the
query.

Practices for Lesson 4

Oracle University and TechnoLogica use only

This practice provides a variety of exercises using TO_CHAR and TO_DATE functions, and
conditional expressions such as DECODE and CASE. Remember that for nested functions,
the results are evaluated from the innermost function to the outermost function.

Oracle Database: SQL Fundamentals I A - 35

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Format the dates to appear in the format similar to “Monday. hire date. the Thirty-First of July. and salary review date. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 1) Create a report that produces the following for each employee: <employee last name> earns <salary> monthly but wants <3 times salary.>. Label the column REVIEW. starting with Monday.Practice 4-1: Using Conversion Functions and Conditional Expressions … 2) Display each employee’s last name. and day of the week on which the employee started. Label the column Dream Salaries.36 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 2000. Order the results by the day of the week. . … Oracle Database: SQL Fundamentals I A . which is the first Monday after six months of service.” … 3) Display the last name. Label the column DAY. hire date.

” Label the column COMM.37 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. show “No Commission. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 4) Create a query that displays the employees’ last names and commission amounts. If an employee does not earn commission. . using the following data: Job Grade AD_PRES ST_MAN IT_PROG SA_REP ST_CLERK None of the above A B C D E 0 … … Oracle Database: SQL Fundamentals I A . complete the following exercises: 5) Using the DECODE function. write a query that displays the grade of all employees based on the value of the column JOB_ID.Practice 4-1: Using Conversion Functions and Conditional Expressions (continued) … If you have time.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Practice 4-1: Using Conversion Functions and Conditional Expressions (continued) 6) Rewrite the statement in the preceding exercise by using the CASE syntax.38 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Oracle University and TechnoLogica use only … … Oracle Database: SQL Fundamentals I A .

999. If an employee does not earn commission.” Label the column COMM. 5) Using the DECODE function. hire date. TO_CHAR(hire_date.00') || '. "the" Ddspth "of" Month. hire date.Practice Solutions 4-1: Using Conversion Functions and Conditional Expressions 1) Create a report that produces the following for each employee: <employee last name> earns <salary> monthly but wants <3 times salary. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT . 'fm$99. SELECT last_name. and salary review date. Label the column DAY. hire_date. 4) Create a query that displays the employees’ last names and commission amounts. 'fmDay. hire_date.' "Dream Salaries" employees.” SELECT last_name. 'fm$99. YYYY') REVIEW FROM employees. TO_CHAR(NEXT_DAY(ADD_MONTHS(hire_date. which is the first Monday after six months of service. Format the dates to appear in the format similar to “Monday. Label the column REVIEW. 2000. NVL(TO_CHAR(commission_pct). write a query that displays the grade of all employees based on the value of the JOB_ID column.1. starting with Monday.999. 'DAY') DAY FROM employees ORDER BY TO_CHAR(hire_date . 'd'). and day of the week on which the employee started.39 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 'No Commission') COMM FROM employees.00') || ' monthly but wants ' || TO_CHAR(salary * 3. 3) Display the last name. SELECT last_name.>. the Thirty-First of July. using the following data: Job Grade AD_PRES ST_MAN IT_PROG SA_REP ST_CLERK None of the above A B C D E 0 Oracle Database: SQL Fundamentals I A . 2) Display each employee’s last name. 6). FROM last_name || ' earns ' || TO_CHAR(salary.'MONDAY'). show “No Commission. Order the results by the day of the week. Label the column Dream Salaries.

'ST_CLERK'. 'E'. 'ST_MAN'. 'SA_REP'.Practice Solutions 4-1: Using Conversion Functions and Conditional Expressions (continued) SELECT job_id. decode (job_id. 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' Oracle Database: SQL Fundamentals I A . '0')GRADE FROM employees. CASE WHEN WHEN WHEN WHEN WHEN ELSE FROM employees. 'AD_PRES'.40 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. SELECT job_id. 'IT_PROG'. 'C'. 'A'. 'B'. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 6) Rewrite the statement in the preceding exercise by using the CASE syntax. 'D'. .

Oracle Database: SQL Fundamentals I A . you should be familiar with using group functions and selecting groups of data.Practices for Lesson 5 Oracle University and TechnoLogica use only At the end of this practice. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .41 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

sql.sql again. Run the statement in lab_05_05. and average salary of all employees.sql. True/False 2) Group functions include nulls in calculations. Round your results to the nearest whole number. 5) Modify the query in lab_05_04. Label the columns Maximum. Oracle Database: SQL Fundamentals I A .Practice 5-1: Reporting Aggregated Data Using the Group Functions Determine the validity of the following three statements. and average salary for each job type. Save your SQL statement as lab_05_04. 1) Group functions work across many rows to produce one result per group. Run the query. respectively. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 3) The WHERE clause restricts rows before inclusion in a group calculation.sql as lab_05_05.42 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. sum. and Average. True/False The HR department needs the following reports: 4) Find the highest. Sum. sum. lowest. Save lab_05_04. maximum. Circle either True or False. Minimum.sql to display the minimum. True/False .

Save the script to a file named lab_05_06. Label the column Number of Managers. Hint: Use the MANAGER_ID column to determine the number of managers. complete the following exercises: 9) Create a report to display the manager number and the salary of the lowest-paid employee for that manager. Oracle Database: SQL Fundamentals I A . .sql.43 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Run the query. Exclude any groups where the minimum salary is $6. Exclude anyone whose manager is not known.Practice 5-1: Reporting Aggregated Data Using the Group Functions (continued) Generalize the query so that the user in the HR department is prompted for a job title. If you have time. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 6) Write a query to display the number of people with the same job. Enter IT_PROG when prompted. 8) Find the difference between the highest and lowest salaries. Sort the output in descending order of salary. Label the column DIFFERENCE.000 or less. 7) Determine the number of managers without listing them.

complete the following exercises: 10) Create a query to display the total number of employees and. and 1998. 1997. Oracle Database: SQL Fundamentals I A .44 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Oracle University and TechnoLogica use only 11) Create a matrix query to display the job. and the total salary for that job. the number of employees hired in 1995. and 90. of that total. 80. giving each column an appropriate heading. the salary for that job based on department number. for departments 20. 1996. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Practice 5-1: Reporting Aggregated Data Using the Group Functions (continued) If you want an extra challenge. 50. Create appropriate column headings.

"Sum". COUNT(*) FROM employees WHERE job_id = '&job_title' GROUP BY job_id. "Minimum".45 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 3) The WHERE clause restricts rows before inclusion in a group calculation. SELECT job_id. True/False 2) Group functions include nulls in calculations. COUNT(*) FROM employees GROUP BY job_id. Run the statement in lab_05_05. sum. SELECT job_id. "Sum". Save your SQL statement as lab_05_04. and average salary for each job type. SELECT ROUND(MAX(salary). "Maximum". lowest.0) ROUND(SUM(salary).sql as lab_05_05. "Minimum". "Average" 6) Write a query to display the number of people with the same job. Sum.0) FROM employees GROUP BY job_id. and Average. Generalize the query so that the user in the HR department is prompted for a job title. True/False . Run the query. Enter IT_PROG when prompted and click OK.Practice Solutions 5-1: Reporting Aggregated Data Using the Group Functions Determine the validity of the following three statements. Round your results to the nearest whole number. Save lab_05_04. "Average" 5) Modify the query in lab_05_04. Save the script to a file named lab_05_06. "Maximum".0) ROUND(MIN(salary). Run the query.sql to display the minimum. Minimum.sql.0) FROM employees. Circle either True or False.sql.0) ROUND(SUM(salary).sql. Oracle Database: SQL Fundamentals I A .0) ROUND(AVG(salary). 1) Group functions work across many rows to produce one result per group. Label the columns Maximum.0) ROUND(MIN(salary). and average salary of all employees. respectively.0) ROUND(AVG(salary).sql again. ROUND(MAX(salary). SELECT job_id. maximum. sum. True/False The HR department needs the following reports: 4) Find the highest.

SUM(DECODE(TO_CHAR(hire_date.1998. If you have the time. of that total.1. SUM(DECODE(TO_CHAR(hire_date. Create appropriate column headings. Hint: Use the MANAGER_ID column to determine the number of managers.1. Exclude anyone whose manager is not known.0))"1998" FROM employees.MIN(salary) DIFFERENCE employees. If you want an extra challenge. SELECT COUNT(DISTINCT manager_id) "Number of Managers" FROM employees. SUM(DECODE(TO_CHAR(hire_date. SELECT COUNT(*) total. 8) Find the difference between the highest and lowest salaries. 'YYYY').000 or less. and 1998. 'YYYY'). the number of employees hired in 1995.Practice Solutions 5-1: Reporting Aggregated Data Using the Group Functions (continued) 7) Determine the number of managers without listing them. 'YYYY').46 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.0))"1996".1.0))"1997". SELECT FROM WHERE GROUP BY HAVING ORDER BY manager_id.0))"1995". 1997. complete the following exercises: 9) Create a report to display the manager number and the salary of the lowest-paid employee for that manager.1995. Exclude any groups where the minimum salary is $6. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT FROM . 1996.1997. 'YYYY'). SUM(DECODE(TO_CHAR(hire_date. complete the following exercises: 10) Create a query that will display the total number of employees and.1996. Sort the output in descending order of salary. Label the column Number of Managers. Label the column DIFFERENCE.1. MAX(salary) . Oracle Database: SQL Fundamentals I A . MIN(salary) employees manager_id IS NOT NULL manager_id MIN(salary) > 6000 MIN(salary) DESC.

. 80. . 50. 90". giving each column an appropriate heading. . 20.Practice Solutions 5-1: Reporting Aggregated Data Using the Group Functions (continued) 11) Create a matrix query to display the job. 50". salary)) salary)) salary)) salary)) Oracle Database: SQL Fundamentals I A . . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and 90. 90. 50. 80. the salary for that job based on the department number. 80".47 "Dept "Dept "Dept "Dept 20". SELECT . for departments 20. 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. and the total salary for that job. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only job_id "Job".

Oracle Database: SQL Fundamentals I A .Practices for Lesson 6 Oracle University and TechnoLogica use only This practice is intended to give you experience in extracting data from more than one table using the SQL:1999–compliant joins. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .48 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

and department name for these employees. 4) Create a report to display employees’ last name and employee number along with their manager’s last name and manager number. respectively. state or province. city. and Mgr#. … 3) The HR department needs a report of employees in Toronto. and country in the output. department number. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 1) Write a query for the HR department to produce the addresses of all the departments. Run the query.49 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Use a NATURAL JOIN to produce the results. Emp#. job. Manager. department number. Label the columns Employee. and the department name for all employees who work in Toronto.sql. … Oracle Database: SQL Fundamentals I A . Use the LOCATIONS and COUNTRIES tables.Practice 6-1: Displaying Data from Multiple Tables Using Joins 2) The HR department needs a report of only those employees with corresponding departments. street address. Write a query to display the last name. Save your SQL statement as lab_06_04. Show the location ID. . Display the last name.

and grade for all employees. To familiarize yourself with the JOB_GRADES table. Oracle Database: SQL Fundamentals I A .sql.50 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. salary. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 5) Modify lab_06_04. and all the employees who work in the same department as a given employee. job. who has no manager. Order the results by the employee number.sql to display all employees including King.Practice 6-1: Displaying Data from Multiple Tables Using Joins (continued) … 6) Create a report for the HR department that displays employee last names. Then create a query that displays the name. Run the query in lab_06_05. … 7) The HR department needs a report on job grades and salaries. department name.sql. Save the script to a file named lab_06_06. Give each column an appropriate label.sql. first show the structure of the JOB_GRADES table. . department numbers. Save your SQL statement as lab_06_05.

Practice 6-1: Displaying Data from Multiple Tables Using Joins (continued) If you want an extra challenge. Oracle Database: SQL Fundamentals I A . Create a query to display the name and hire date of any employee hired after employee Davies. complete the following exercises: 8) The HR department wants to determine the names of all the employees who were hired after Davies. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only … . 9) The HR department needs to find the names and hire dates of all the employees who were hired before their managers. along with their managers’ names and hire dates. Save the script to a file named lab_06_09.51 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.sql.

manager_id = m. m. d.location_id) WHERE LOWER(l. and department name for all employees who work in Toronto. state_province. Run the query in lab_06_05. department number. Save your SQL statement as lab_06_05.sql to display all employees including King. Write a query to display the last name. Use the LOCATIONS and COUNTRIES tables. Order the results by the employee number.52 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT location_id. 2) The HR department needs a report of all employees. department_id. m. e. job. who has no manager.department_id = d. 5) Modify lab_06_04. m.employee_id) ORDER BY 2. and Mgr#.last_name "Employee". Manager.department_id. Use a NATURAL JOIN to produce the results. Label the columns Employee. state or province.last_name "Manager".employee_id "Mgr#" FROM employees w LEFT OUTER JOIN employees m ON (w. w.employee_id).department_name FROM employees e JOIN departments d ON (e. and country in the output. SELECT w. Save your SQL statement as lab_06_04. city.manager_id = m. SELECT w. SELECT last_name. city.Practice Solutions 6-1: Displaying Data from Multiple Tables Using Joins 1) Write a query for the HR department to produce the addresses of all the departments.employee_id "Mgr#" FROM employees w join employees m ON (w. m. SELECT e.city) = 'toronto'.sql. Display the last name. Emp#. street_address. country_name FROM locations NATURAL JOIN countries. Run the query.sql. w.sql. department_name FROM employees JOIN departments USING (department_id).last_name "Manager".last_name "Employee".job_id. 4) Create a report to display employees’ last names and employee number along with their managers’ last names and manager number. e. Oracle Database: SQL Fundamentals I A . street address.employee_id "EMP#". 3) The HR department needs a report of employees in Toronto. respectively.last_name. .employee_id "EMP#". and department name for all the employees.location_id = l. department number. Show the location ID.department_id) JOIN locations l ON (d.

last_name colleague FROM employees e JOIN employees c ON (e. e. 9) The HR department needs to find the names and hire dates for all employees who were hired before their managers.last_name. m. Oracle Database: SQL Fundamentals I A . c. w.last_name = 'Davies') davies.last_name. Then create a query that displays the name.last_name.department_id = d.manager_id = m. Save the script to a file named lab_06_06. salary. DESC JOB_GRADES SELECT e. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT e.hire_date employees e JOIN employees davies (davies. and grade for all employees. SELECT FROM ON WHERE e. j.salary.highest_sal). m.53 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.employee_id) WHERE w. e. along with their managers’ names and hire dates.hire_date FROM employees w JOIN employees m ON (w.department_id. Give each column an appropriate label. first show the structure of the JOB_GRADES table.department_id department. department numbers.department_name. complete the following exercises: 8) The HR department wants to determine the names of all employees who were hired after Davies. Save the script to a file named lab_06_09.last_name employee. To familiarize yourself with the JOB_GRADES table.hire_date < m.hire_date.hire_date.department_id = c.sql.lowest_sal AND j. job. c.employee_id ORDER BY e.last_name.last_name. e. SELECT w. e.employee_id <> c. .sql.Practice Solutions 6-1: Displaying Data from Multiple Tables Using Joins (continued) 6) Create a report for the HR department that displays employee last names.hire_date.department_id) JOIN job_grades j ON (e. 7) The HR department needs a report on job grades and salaries. Create a query to display the name and hire date of any employee hired after employee Davies. Run the query. d.hire_date < e.last_name. department name. and all the employees who work in the same department as a given employee. If you want an extra challenge. e.salary BETWEEN j.department_id) WHERE e.job_id.grade_level FROM employees e JOIN departments d ON (e.

you may want to create the inner query first. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .54 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practices for Lesson 7 Oracle University and TechnoLogica use only In this practice. Make sure that it runs and produces the data that you anticipate before you code the outer query. you write complex queries using nested SELECT statements. Oracle Database: SQL Fundamentals I A . For practice questions.

3) 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. Sort the results in order of ascending salary. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 1) The HR department needs a query that prompts the user for an employee last name. if the user enters Zlotkey.sql.” Save your SQL statement as lab_07_03. and salary of all employees who earn more than the average salary. For example. Oracle Database: SQL Fundamentals I A . last name. find all employees who work with Zlotkey (excluding Zlotkey). The query then displays the last name and hire date of any employee in the same department as the employee whose name they supply (excluding that employee).55 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. .Practice 7-1: Using Subqueries to Solve Queries 2) Create a report that displays the employee number. Run your query.

and job ID for every employee in the Executive department.sql to display the employee number.56 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.” Save lab_07_03. . and job ID of all employees whose department location ID is 1700. last name.Practice 7-1: Using Subqueries to Solve Queries (continued) Modify the query so that the user is prompted for a location ID. Run the statement in lab_07_08. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 4) The HR department needs a report that displays the last name.sql again. department number.sql.sql. Oracle Database: SQL Fundamentals I A . 6) Create a report for HR that displays the department number.sql as lab_07_08. and salary of all employees who earn more than the average salary. Save this to a file named lab_07_04. 5) Create a report for HR that displays the last name and salary of every employee who reports to King. and who work in a department with any employee whose last name contains a “u. complete the following exercise: 8) Modify the query in lab_07_03. 7) Create a report that displays a list of all employees whose salary is more than the salary of any employee from department 60. If you have the time. last name.

Sort the results in order of ascending salary. SELECT last_name.Practice Solutions 7-1: Using Subqueries to Solve Queries 1) The HR department needs a query that prompts the user for an employee last name. last_name. 2) Create a report that displays the employee number. SELECT employee_id. department number. job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = 1700). For example. The query then displays the last name and hire date of any employee in the same department as the employee whose name they supply (excluding that employee). find all employees who work with Zlotkey (excluding Zlotkey). salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees) ORDER BY salary. 4) The HR department needs a report that displays the last name. if the user enters Zlotkey. last_name FROM employees WHERE department_id IN (SELECT department_id FROM employees WHERE last_name like '%u%'). and salary of all employees who earn more than the average salary. 3) 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 a “u. Run your query.57 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.” Save your SQL statement as lab_07_03. SELECT employee_id. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only UNDEFINE Enter_name . and job ID of all employees whose department location ID is 1700. SELECT last_name. department_id. hire_date FROM employees WHERE department_id = (SELECT department_id FROM employees WHERE last_name = '&&Enter_name') AND last_name <> '&Enter_name'. last name.sql. Oracle Database: SQL Fundamentals I A .

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 a “u. salary FROM employees WHERE department_id IN (SELECT department_id FROM employees WHERE last_name like '%u%') AND salary > (SELECT AVG(salary) FROM employees). and job ID for every employee in the Executive department. If you have the time. SELECT employee_id. department_id. last_name. 6) Create a report for HR that displays the department number.sql.sql to display the employee number. Run the statement in lab_07_08.58 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practice Solutions 7-1: Using Subqueries to Solve Queries (continued) Modify the query so that the user is prompted for a location ID.sql again. last name. Oracle Database: SQL Fundamentals I A . salary FROM employees WHERE manager_id = (SELECT employee_id FROM employees WHERE last_name = 'King'). SELECT last_name. SELECT last_name. job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = &Enter_location).” Save lab_07_03. . 7) Create a report that displays a list of all employees whose salary is more than the salary of any employee from department 60. complete the following exercise: 8) Modify the query in lab_07_03. last name. job_id FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE department_name = 'Executive').sql to lab_07_08. last_name.sql. SELECT department_id. SELECT last_name FROM employees WHERE salary > ANY (SELECT salary FROM employees WHERE department_id=60). Save this to a file named lab_07_04. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 5) Create a report for HR that displays the last name and salary of every employee who reports to King.

Oracle Database: SQL Fundamentals I A . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED . you write queries using the set operators.Practices for Lesson 8 Oracle University and TechnoLogica use only In this practice.59 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

Practice 8-1: Using the Set Operators

2) The HR department needs a list of countries that have no departments located in
them. Display the country ID and the name of the countries. Use the set operators to
create this report.

3) Produce a list of jobs for departments 10, 50, and 20, in that order. Display the job ID
and department ID by using the set operators.

4) Create a report that lists the employee IDs and job IDs of those employees who
currently have a job title that is the same as their job title when they were initially
hired by the company (that is, they changed jobs, but have now gone back to doing
their original job).

5) The HR department needs a report with the following specifications:

Last name and department ID of all employees from the EMPLOYEES table,
regardless of whether or not they belong to a department

Department ID and department name of all departments from the DEPARTMENTS
table, regardless of whether or not they have employees working in them

Write a compound query to accomplish this.

Oracle Database: SQL Fundamentals I A - 60

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

1) The HR department needs a list of department IDs for departments that do not contain
the job ID ST_CLERK. Use the set operators to create this report.

Oracle University and TechnoLogica use only

Practice 8-1: Using the Set Operators (continued)

Oracle Database: SQL Fundamentals I A - 61

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Practice Solutions 8-1: Using the Set Operators
1) The HR department needs a list of department IDs for departments that do not contain
the job ID ST_CLERK. Use the set operators to create this report.
department_id
departments
department_id
employees
job_id = 'ST_CLERK';

2) The HR department needs a list of countries that have no departments located in
them. Display the country ID and the name of the countries. Use the set operators to
create this report.
SELECT country_id,country_name
FROM countries
MINUS
SELECT l.country_id,c.country_name
FROM locations l JOIN countries c
ON (l.country_id = c.country_id)
JOIN departments d
ON d.location_id=l.location_id;

3) Produce a list of jobs for departments 10, 50, and 20, in that order. Display job ID and
department ID using the set operators.
SELECT distinct job_id, department_id
FROM employees
WHERE department_id = 10
UNION ALL
SELECT DISTINCT job_id, department_id
FROM employees
WHERE department_id = 50
UNION ALL
SELECT DISTINCT job_id, department_id
FROM employees
WHERE department_id = 20

4) Create a report that lists the employee IDs and job IDs of those employees who
currently have a job title that is the same as their job title when they were initially
hired by the company (that is, they changed jobs, but have now gone back to doing
their original job).
SELECT
employee_id,job_id
FROM
employees
INTERSECT
SELECT
employee_id,job_id
FROM
job_history;

Oracle Database: SQL Fundamentals I A - 62

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

SELECT
FROM
MINUS
SELECT
FROM
WHERE

Practice Solutions 8-1: Using the Set Operators (continued)
5) The HR department needs a report with the following specifications:

Last name and department ID of all the employees from the EMPLOYEES table,
regardless of whether or not they belong to a department

Department ID and department name of all the departments from the
DEPARTMENTS table, regardless of whether or not they have employees working
in them

SELECT last_name,department_id,TO_CHAR(null)
FROM
employees
UNION
SELECT TO_CHAR(null),department_id,department_name
FROM departments;

Oracle Database: SQL Fundamentals I A - 63

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

Write a compound query to accomplish this.

Practices for Lesson 9

Oracle University and TechnoLogica use only

In this practice, you add rows to the MY_EMPLOYEE table, update and delete data from the
table, and control your transactions. You run a script to create the MY_EMPLOYEE table.

Oracle Database: SQL Fundamentals I A - 64

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle Database: SQL Fundamentals I A . 2) Describe the structure of the MY_EMPLOYEE table to identify the column names. As a prototype. and delete employee data. 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 3) Create an INSERT statement to add the first row of data to the MY_EMPLOYEE table from the following sample data.sql script to build the MY_EMPLOYEE table used in this practice. Do not enter all rows yet. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Insert data into the MY_EMPLOYEE table. Note: For all the DML statements. you use the MY_EMPLOYEE table before giving the statements to the HR department. 1) Run the statement in the lab_09_01. For SELECT queries. use the Run Script icon (or press [F5]) to execute the query.Practice 9-1: Manipulating Data The HR department wants you to create SQL statements to insert. update.65 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Do not list the columns in the INSERT clause. . continue to use the Execute Statement icon or press [F9] to get the formatted output on the Results tabbed page. This way you get to see the feedback messages on the Script Output tabbed page.

66 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 10) Change the last name of employee 3 to Drexler. . Oracle Database: SQL Fundamentals I A . 7) 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. LAST_NAME. 12) Verify your changes to the table. This time. list the columns explicitly in the INSERT clause. USERID. 9) Make the data additions permanent. Update and delete data in the MY_EMPLOYEE table. 8) Confirm your additions to the table. 6) Write an INSERT statement in a dynamic reusable script file to load the remaining rows into the MY_EMPLOYEE table.Practice 9-1: Manipulating Data (continued) 4) Populate the MY_EMPLOYEE table with the second row of the sample data from the preceding list. 14) Confirm your changes to the table. 11) Change the salary to $1. FIRST_NAME. and SALARY). 13) Delete Betty Dancs from the MY_EMPLOYEE table.000 for all employees who have a salary less than $900. Save this script to a lab_09_06. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 5) Confirm your addition to the table. The script should prompt for all the columns (ID.sql file.

sql.67 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Therefore. Run the statements in the script. 23) Make the data addition permanent. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 16) 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. The generated USERID must be in lowercase. If you have the time. . the script should not prompt for the USERID.Practice 9-1: Manipulating Data (continued) 15) Commit all pending changes. 19) Delete all the rows from the MY_EMPLOYEE table. Save this script to a file named lab_09_24. complete the following exercise: 24) Modify the lab_09_06. 20) Confirm that the table is empty. 18) Mark an intermediate point in the processing of the transaction. ID LAST_NAME FIRST_NAME USERID SALARY 6 Anthony Mark manthony 1230 Oracle Database: SQL Fundamentals I A . Control data transaction to the MY_EMPLOYEE table. 22) Confirm that the new row is still intact. 17) Confirm your addition to the table. 21) Discard the most recent DELETE operation without discarding the earlier INSERT operation.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.

68 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED . Oracle Database: SQL Fundamentals I A .sql script to insert the following record: Oracle University and TechnoLogica use only 26) Confirm that the new row was added with correct USERID.Practice 9-1: Manipulating Data (continued) 25) Run the lab_09_24.

b) After the statement is opened in a SQL Worksheet. 'Dancs'.69 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 1) Run the statement in the lab_09_01. In the Open dialog box. navigate to the /home/oracle/labs/sql1/labs folder. 860). 'Patel'. DESCRIBE my_employee 3) Create an INSERT statement to add the first row of data to the MY_EMPLOYEE table from the following sample data. 895).sql. . Do not list the columns in the INSERT clause. click the Run Script icon to run the script. last_name. first_name. SELECT FROM * my_employee. 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 INSERT INTO my_employee VALUES (1. Oracle Database: SQL Fundamentals I A . and then double-click lab_09_01. You get a Create Table succeeded message on the Script Output tabbed page. userid. 4) Populate the MY_EMPLOYEE table with the second row of the sample data from the preceding list. INSERT INTO my_employee (id. 'bdancs'.sql script to build the MY_EMPLOYEE table used in this practice.Practice Solutions 9-1: Manipulating Data Insert data into the MY_EMPLOYEE table. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only a) From File menu. 'Ralph'. This time. select Open. 2) Describe the structure of the MY_EMPLOYEE table to identify the column names. 'rpatel'. 'Betty'. list the columns explicitly in the INSERT clause. salary) VALUES (2. 5) Confirm your additions to the table.

USERID. FIRST_NAME. '&p_userid'. '&p_first_name'. . Save this script to a file named lab_09_06. Oracle Database: SQL Fundamentals I A . The script should prompt for all the columns (ID. INSERT INTO my_employee VALUES (&p_id.Practice Solutions 9-1: Manipulating Data (continued) 6) Write an INSERT statement in a dynamic reusable script file to load the remaining rows into the MY_EMPLOYEE table. LAST_NAME. UPDATE SET WHERE my_employee salary = 1000 salary < 900. '&p_last_name'. and SALARY). UPDATE SET WHERE my_employee last_name = 'Drexler' id = 3. Update and delete data in the MY_EMPLOYEE table. '&p_userid'. &p_salary).sql. '&p_last_name'. 9) Make the data additions permanent. SELECT * FROM my_employee.000 for all employees with a salary less than $900. '&p_first_name'. 10) Change the last name of employee 3 to Drexler. 11) Change the salary to $1. COMMIT. 12) Verify your changes to the table. SELECT FROM * my_employee. DELETE FROM my_employee WHERE last_name = 'Dancs'. &p_salary).70 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 13) Delete Betty Dancs from the MY_EMPLOYEE table. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 7) Populate the table with the next two rows of sample data listed in step 3 by running the INSERT statement in the script that you created. INSERT INTO my_employee VALUES (&p_id. 8) Confirm your additions to the table. 14) Confirm your changes to the table. SELECT FROM * my_employee.

SELECT * FROM my_employee. 21) Discard the most recent DELETE operation without discarding the earlier INSERT operation. .71 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. '&p_first_name'. INSERT INTO my_employee VALUES (&p_id. COMMIT. '&p_userid'. DELETE FROM my_employee. 19) Delete all the rows from the MY_EMPLOYEE table. SAVEPOINT step_17. 20) Confirm that the table is empty. Run the statements in the script. COMMIT. 18) Mark an intermediate point in the processing of the transaction. 16) 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. 22) Confirm that the new row is still intact. SELECT * FROM my_employee. Control data transaction to the MY_EMPLOYEE table. Oracle Database: SQL Fundamentals I A . '&p_last_name'. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 17) Confirm your addition to the table. ROLLBACK TO step_17. &p_salary).Practice Solutions 9-1: Manipulating Data (continued) 15) Commit all pending changes. SELECT FROM * my_employee. 23) Make the data addition permanent.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 24) Modify the lab_09_06. complete the following exercise: SET ECHO OFF SET VERIFY OFF INSERT INTO my_employee VALUES (&p_id.Practice Solutions 9-1: Manipulating Data (continued) If you have time.sql.sql script to insert the following record: ID LAST_NAME FIRST_NAME USERID SALARY 6 Anthony Mark manthony 1230 26) Confirm that the new row was added with the correct USERID. 1. The generated USERID must be in lowercase. . 1) || substr('&p_last_name'. &p_salary). SET VERIFY ON SET ECHO ON UNDEFINE p_first_name UNDEFINE p_last_name 25) Run the lab_09_24. '&&p_first_name'. '&&p_last_name'. Save this script to a file named lab_09_24. the script should not prompt for the USERID.72 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Therefore. SELECT * FROM my_employee WHERE ID='6'. 1. lower(substr('&p_first_name'. Oracle Database: SQL Fundamentals I A . 7)).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.

Note: For all the DDL and DML statements. continue to click the Execute Statement icon or press [F9] to get the formatted output on the Results tabbed page. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED . You also learn to set the status of a table as READ ONLY and then revert to READ/WRITE.73 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Oracle Database: SQL Fundamentals I A . For SELECT queries.Practices for Lesson 10 Oracle University and TechnoLogica use only Create new tables by using the CREATE TABLE statement. This way you get to see the feedback messages on the Script Output tabbed page. Confirm that the new table was added to the database. click the Run Script icon (or press [F5]) to execute the query in SQL Developer.

sql.sql. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only FK Table . Confirm that the table is created.Practice 10-1: Using DDL Statements to Create and Manage Tables Column Name ID NAME Key Type Primary key Nulls/Unique FK Column Data type NUMBER VARCHAR2 Length 7 25 1) Create the DEPT table based on the following table instance chart. Include only columns that you need. Save the statement in a script called lab_10_01.74 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 2) Populate the DEPT table with data from the DEPARTMENTS table. Confirm that the table is created. and then execute the statement in the script to create the table. 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 Oracle Database: SQL Fundamentals I A . and then execute the statement in the script to create the table. 3) Create the EMP table based on the following table instance chart. Save the statement in a script called lab_10_03.

Name the columns in your new table ID. FIRST_NAME.Practice 10-1: Using DDL Statements to Create and Manage Tables (continued) 5) Alter the EMPLOYEES2 table status to read-only. respectively. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 4) Create the EMPLOYEES2 table based on the structure of the EMPLOYEES table. SALARY. You should get the following messages: 8) Drop the EMPLOYEES2 table. LAST_NAME. LAST_NAME. Now. ID FIRST_NAME LAST_NAME SALARY DEPT_ID 34 Grant Marcie 5678 10 6) Try to insert the following row in the EMPLOYEES2 table: You get the following error message: 7) Revert the EMPLOYEES2 table to the read/write status. Include only the EMPLOYEE_ID.75 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. FIRST_NAME. Please note that this option is supported in Oracle Database 11g. try to insert the same row again. Please note that this option is supported in Oracle Database 11g. and DEPARTMENT_ID columns. Oracle Database: SQL Fundamentals I A . and DEPT_ID. SALARY. .

and then execute the statement in the script to create the table. name VARCHAR2(25)). Include only those columns that you need.sql. Confirm that the table is created. department_name FROM departments. Save the statement in a script called lab_10_03. 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 Oracle Database: SQL Fundamentals I A . Confirm that the table is created. Save the statement in a script called lab_10_01. 3) Create the EMP table based on the following table instance chart. To confirm that the table was created and to view its structure.76 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practice Solutions 10-1: Using DDL Statements to Create and Manage Tables Column Name ID NAME Key Type Primary key Nulls/Unique FK Column Data type NUMBER VARCHAR2 Length 7 25 1) Create the DEPT table based on the following table instance chart. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only FK Table . INSERT INTO dept SELECT department_id. CREATE TABLE dept (id NUMBER(7)CONSTRAINT department_id_pk PRIMARY KEY.sql. and then execute the statement in the script to create the table. issue the following command: DESCRIBE dept 2) Populate the DEPT table with data from the DEPARTMENTS table.

ID FIRST_NAME LAST_NAME SALARY DEPT_ID 34 Grant Marcie 5678 10 Note. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only To confirm that the table was created and to view its structure: . and DEPT_ID. FIRST_NAME. LAST_NAME. INSERT INTO employees2 VALUES (34. last_name VARCHAR2(25). respectively. 'Grant'. you will be allowed to insert a row into the table. Name the columns in your new table ID. you will get the “Update operation not allowed on table” error message. first_name. CREATE TABLE employees2 AS SELECT employee_id id. 5) Alter the EMPLOYEES2 table status to read-only. you will not be allowed to insert any row into the table because it is assigned a read-only status.Practice Solutions 10-1: Using DDL Statements to Create and Manage Tables (continued) CREATE TABLE emp (id NUMBER(7). DESCRIBE emp 4) Create the EMPLOYEES2 table based on the structure of the EMPLOYEES table.'Marcie'. and DEPARTMENT_ID columns. because the table is assigned a READ WRITE status.5678. Now. first_name VARCHAR2(25). salary.10) 7) Revert the EMPLOYEES2 table to the read/write status. department_id dept_id FROM employees.77 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Therefore. ALTER TABLE employees2 READ WRITE INSERT INTO employees2 VALUES (34. FIRST_NAME. Include only the EMPLOYEE_ID. dept_id NUMBER(7) CONSTRAINT emp_dept_id_FK REFERENCES dept (id) ). LAST_NAME. last_name. SALARY.5678. ALTER TABLE employees2 READ ONLY 6) Try to insert the following row in the EMPLOYEES2 table. Now try to insert the same row again. 'Grant'.10) Oracle Database: SQL Fundamentals I A . SALARY.'Marcie'.

78 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. To test this. The table EMPLOYEES2 will be dropped. Oracle Database: SQL Fundamentals I A . alter the table again to READ ONLY status. Oracle University and TechnoLogica use only DROP TABLE employees2. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Practice Solutions 10-1: Using DDL Statements to Create and Manage Tables (continued) 8) Drop the EMPLOYEES2 table. and then issue the DROP TABLE command. Note: You can even drop a table that is in the READ ONLY mode.

and a synonym. Part 2 of this lesson’s practice provides you with a variety of exercises in creating and using a sequence. an index. using. Oracle Database: SQL Fundamentals I A . Complete questions 1–6 of this lesson. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED . and removing views.Practices for Lesson 11 Oracle University and TechnoLogica use only Part 1 of this lesson’s practice provides you with a variety of exercises in creating. Complete questions 7–10 of this lesson.79 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 2) Confirm that the view works.Practice 11-1: Creating Other Schema Objects Part 1 1) The staff in the HR department wants to hide some of the data in the EMPLOYEES table. do not allow an employee to be reassigned to another department through the view. employee last names. write a query for the HR department to display all employee names and department numbers. For security purposes. Oracle Database: SQL Fundamentals I A . The heading for the employee name should be EMPLOYEE. … 4) Department 50 needs access to its employee data. .80 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and DEPTNO. and department numbers for all employees in department 50. You have been asked to label the view columns EMPNO. Create a view called EMPLOYEES_VU based on the employee numbers. EMPLOYEE. Create a view named DEPT50 that contains the employee numbers. employee last names. Display the contents of the EMPLOYEES_VU view. 5) Display the structure and contents of the DEPT50 view. … 3) Using your EMPLOYEES_VU view. and department numbers from the EMPLOYEES table.

81 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Part 2 . 8) To test your sequence. Add two departments: Education and Administration. 10) Create a synonym for your EMPLOYEES table.000. 7) You need a sequence that can be used with the PRIMARY KEY column of the DEPT table. Confirm your additions. Attempt to reassign Matos to department 80. Be sure to use the sequence that you created for the ID column.Practice 11-1: Creating Other Schema Objects (continued) 6) Test your view. The sequence should start at 200 and have a maximum value of 1. Oracle Database: SQL Fundamentals I A . 9) Create a nonunique index on the NAME column in the DEPT table. Call it EMP. Have your sequence increment by 10. Name your script lab_11_08. write a script to insert two rows in the DEPT table.sql. Name the sequence DEPT_ID_SEQ. Run the commands in your script.

4) Department 50 needs access to its employee data. last_name employee. SELECT FROM * employees_vu. Display the contents of the EMPLOYEES_VU view. employee last names. and DEPTNO. last_name employee. SELECT FROM employee. department_id employees_vu. They have requested that you label the view columns EMPNO. Attempt to reassign Matos to department 80. 6) Test your view. 3) Using your EMPLOYEES_VU view.Practice Solutions 11-1: Creating Other Schema Objects Part 1 1) The staff in the HR department wants to hide some of the data in the EMPLOYEES table. This ensures that the DEPTNO column in the view is protected from being changed. write a query for the HR department to display all employee names and department numbers. Create a view called EMPLOYEES_VU based on the employee numbers. Create a view named DEPT50 that contains the employee numbers. The heading for the employee name should be EMPLOYEE. The error is because the DEPT50 view has been created with the WITH CHECK OPTION constraint. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only CREATE OR REPLACE VIEW employees_vu AS SELECT employee_id. do not allow an employee to be reassigned to another department through the view. 2) Confirm that the view works. employee last names. CREATE VIEW dept50 AS SELECT employee_id empno. 5) Display the structure and contents of the DEPT50 view.82 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and department numbers for all employees in department 50. department_id deptno FROM employees WHERE department_id = 50 WITH CHECK OPTION CONSTRAINT emp_dept_50. . and department numbers from the EMPLOYEES table. department_id FROM employees. DESCRIBE dept50 SELECT FROM * dept50. Oracle Database: SQL Fundamentals I A . For security purposes. UPDATE SET WHERE dept50 deptno = 80 employee = 'Matos'. EMPLOYEE.

The sequence should start at 200 and have a maximum value of 1.000. 10) Create a synonym for your EMPLOYEES table. write a script to insert two rows in the DEPT table. Name the sequence DEPT_ID_SEQ. CREATE INDEX dept_name_idx ON dept (name). 8) To test your sequence. Be sure to use the sequence that you created for the ID column. Have your sequence increment by 10.nextval. 'Administration'). COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only CREATE SEQUENCE dept_id_seq START WITH 200 INCREMENT BY 10 MAXVALUE 1000. Confirm your additions.Practice Solutions 11-1: Creating Other Schema Objects (continued) Part 2 7) You need a sequence that can be used with the primary key column of the DEPT table. INSERT INTO dept VALUES (dept_id_seq. Add two departments: Education and Administration.83 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 'Education'). INSERT INTO dept VALUES (dept_id_seq. Call it EMP. Name your script lab_11_08. Oracle Database: SQL Fundamentals I A . CREATE SYNONYM emp FOR EMPLOYEES. 9) Create a nonunique index on the NAME column in the DEPT table. Run the commands in your script.sql. .nextval.

Oracle Database: SQL Fundamentals I A .84 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practices for Appendix F Oracle University and TechnoLogica use only This practice is intended to give you practical experience in extracting data from more than one table using the Oracle join syntax. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .

respectively. Label the columns Employee. and Mgr#. Run the query. Manager. 4) Create a report to display the employees’ last names and employee number along with their managers’ last names and manager number. Show the location ID. . and country in the output. department number. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 1) Write a query for the HR department to produce the addresses of all the departments. Use the LOCATIONS and COUNTRIES tables. and department name for all employees. Run the query. Display the last name. Emp#. Write a query to display the last name.sql. … Oracle Database: SQL Fundamentals I A .Practice F-1: Oracle Join Syntax 2) The HR department needs a report of all employees. job. city.85 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. state or province. street address. department number. … 3) The HR department needs a report of employees in Toronto. Save your SQL statement as lab_f_04. and department name for all employees who work in Toronto.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 5) Modify lab_f_04. To familiarize yourself with the JOB_GRADES table. department numbers.sql. Order the results by the employee number. salary.Practice F-1: Oracle Join Syntax (continued) … 6) Create a report for the HR department that displays employee last names. who has no manager. first show the structure of the JOB_GRADES table.sql to display all employees including King. .sql. Oracle Database: SQL Fundamentals I A . and grade for all employees. … 7) The HR department needs a report on job grades and salaries. Run the query in lab_f_05.86 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Save the script to a file named lab_f_06. Give each column an appropriate label.sql. department name. job. Save your SQL statement as lab_f_05. Then create a query that displays the name. and all employees who work in the same department as a given employee.

sql. 9) The HR department needs to find the names and hire dates for all employees who were hired before their managers. complete the following exercises: 8) The HR department wants to determine the names of all employees who were hired after Davies.87 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. along with their managers’ names and hire dates. Create a query to display the name and hire date of any employee hired after employee Davies. Oracle Database: SQL Fundamentals I A . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only … . Save the script to a file named lab_f_09.Practice F-1: Oracle Join Syntax (continued) If you want an extra challenge.

manager_id = m.last_name.department_id AND d. Oracle Database: SQL Fundamentals I A .last_name. Run the query in lab_f_05.job_id. m.department_id = d. Save the SQL statement as lab_f_05. Run the query. departments d . city.manager_id = m. departments d WHERE e. w.department_name FROM employees e. .sql to display all employees including King. 4) Create a report to display the employee last name and the employee number along with the last name of the employee’s manager and manager number.employee_id (+). Order the results by the employee number. Write a query to display the last name. d.country_id. who has no manager. state or province.last_name "Manager".employee_id "EMP#".department_id. SELECT e.last_name "Employee".employee_id "EMP#". employees m WHERE w.last_name "Manager".department_id. department number. Use the LOCATIONS and COUNTRIES tables. and Mgr#. d. and department name for all employees. e.department_id. SELECT w. SELECT e.employee_id "Mgr#" FROM employees w. Display the last name. and country in the output.location_id = l. Run the query. m. m. 5) Modify lab_f_04. m. Emp#.sql. department number. SELECT location_id. countries WHERE locations. Save your SQL statement as lab_f_04. country_name FROM locations. SELECT w. employees m WHERE w.department_id = d. street_address. and department name for all employees who work in Toronto. job.country_id = countries. state_province. w.Practice Solutions F-1: Oracle Join Syntax 1) Write a query for the HR department to produce the addresses of all the departments. locations l WHERE e.city) = 'toronto'. street address. respectively.88 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.department_name FROM employees e. city.sql. e. e. Manager. Show the location ID.last_name "Employee".employee_id. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 2) The HR department needs a report of all employees. Label the columns Employee.location_id AND LOWER(l. 3) The HR department needs a report of employees in Toronto.employee_id "Mgr#" FROM employees w.sql.

department name. 9) The HR department needs to find the names and hire dates for all employees who were hired before their managers. and Mgr Hired. SELECT FROM WHERE AND w. Then create a query that displays the name.lowest_sal AND j. w. Save the script to a file named lab_f_06. Manager. and grade for all employees. j.salary.hire_date < e. e.hire_date.hire_date.Practice Solutions F-1: Oracle Join Syntax (continued) 6) Create a report for the HR department that displays employee last names. Oracle Database: SQL Fundamentals I A . job.department_name. If you want an extra challenge. SELECT FROM WHERE AND e. employees m w. m. first show the structure of the JOB_GRADES table.89 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.employee_id <> e2.highest_sal. d.sql. e2.job_id. 7) The HR department needs a report on job grades and salaries.last_name employee. e.last_name = 'Davies' davies. employees davies davies. departments d.manager_id = m. Give each column an appropriate label.employee_id ORDER BY e1. along with their managers’ names and hire dates.department_id AND e1.last_name.hire_date < m.last_name.salary BETWEEN j. complete the following exercises: 8) The HR department wants to determine the names of all employees hired after Davies.hire_date employees w .sql. e1.grade_level FROM employees e. m.last_name colleague FROM employees e1. To familiarize yourself with the JOB_GRADES table.hire_date employees e . Emp Hired. . Save the script to a file named lab_f_09.hire_date.last_name.department_id AND e. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT e1.department_id = d. e2.last_name. Create a query to display the name and hire date of any employee hired after Davies. DESC JOB_GRADES SELECT e.department_id department. respectively.last_name. job_grades j WHERE e. Label the columns Employee.employee_id w. department numbers.department_id.last_name. e. and all the employees who work in the same department as a given employee. e1. employees e2 WHERE e1. salary.department_id = e2.

Oracle University and TechnoLogica use only Practice Solutions F-1: Oracle Join Syntax (continued) Oracle Database: SQL Fundamentals I A .90 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Oracle University and TechnoLogica use only Appendix AP Additional Practices and Solutions THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

........................................ 19 Practice Solutions 2-1 ..................... COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .................................................................... 3 Practice 1-1 .........................................Table of Contents Oracle University and TechnoLogica use only Additional Practices .................................. 17 Practice 2-1 ............................... 12 Case Study ............................................................................................................................................................................................................................. 27 Oracle Database: SQL Fundamentals I AP .................................2 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY..................................................................................................... 4 Practice Solutions 1-1 .......................................................................

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .3 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Oracle University and TechnoLogica use only Additional Practices Oracle Database: SQL Fundamentals I AP .

but who have a 10% raise in salary (round off the salaries). and SQL functions. Sort the data by salary in descending order.4 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 2) The HR department needs a report of employees who earn commission. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 1) The HR department needs to find data for all the clerks who were hired after the year 1997. and commission of those employees. The report should display those employees who have no commission. Show the last name.Practice 1-1 These exercises can be used for extra practice after you have discussed the following topics: basic SQL SELECT statement. Oracle Database: SQL Fundamentals I AP . 3) For budgeting purposes. basic SQL Developer commands. salary. . the HR department needs a report on projected raises. job.

Order the report by the length of their employment.” or “M.Practice 1-1 (continued) 5) Show those employees who have a last name starting with the letters “J.” “K. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 4) Create a report of employees and their length of employment. The employee who has been employed the longest should appear at the top of the list. . 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.” Oracle Database: SQL Fundamentals I AP .” “L.5 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

Practice 1-1 (continued)

These exercises can be used for extra practice after you have discussed the following
topics: basic SQL SELECT statement, basic SQL Developer commands, SQL functions,
joins, and group functions.
7) Create a report that displays the department name, location ID, last name, job title,
and salary of those employees who work in a specific location. Prompt the user for
the location. For example, if the user enters 1800, these are the results:

8) Find the number of employees who have a last name that ends with the letter “n.”
Create two possible solutions.

Oracle Database: SQL Fundamentals I AP - 6

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

6) Create a report that displays all employees, and indicate with the words Yes or No
whether they receive a commission. Use the DECODE expression in your query.

Practice 1-1 (continued)

10) The HR department needs to find the job titles in departments 10 and 20. Create a
report to display the job IDs for those departments.

11) Create a report that displays the jobs that are found in the Administration and
Executive departments. Also display the number of employees for these jobs. Show
the job with the highest number of employees first.

These exercises can be used for extra practice after you have discussed the following
topics: basic SQL SELECT statements, basic SQL Developer commands, SQL functions,
joins, group functions, and subqueries.
12) Show all the employees who were hired in the first half of the month (before the 16th
of the month).

Oracle Database: SQL Fundamentals I AP - 7

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

9) Create a report that shows the name, location, and number of employees for each
department. Make sure that the report also includes departments without employees.

Practice 1-1 (continued)

14) Show all the employees who have managers with a salary higher than $15,000. Show
the following data: employee name, manager name, manager salary, and salary grade
of the manager.

Oracle Database: SQL Fundamentals I AP - 8

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

13) Create a report that displays the following for all employees: last name, salary, and
salary expressed in terms of thousands of dollars.

Practice 1-1 (continued)

16) Create a report to display the department number and lowest salary of the department
with the highest average salary.

17) Create a report that displays departments where no sales representatives work.
Include the department number, department name, manager ID, and the location in
the output.

Oracle Database: SQL Fundamentals I AP - 9

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

15) Show the department number, name, number of employees, and average salary of all
the departments, together with the names, salaries, and jobs of the employees working
in each department.

Practice 1-1 (continued)
18) Create the following statistical reports for the HR department: Include the
department number, department name, and the number of employees working in each
department that:
a) Employs fewer than three employees:

c) Has the lowest number of employees:

19) Create a report that displays the employee number, last name, salary, department
number, and the average salary in their department for all employees.

Oracle Database: SQL Fundamentals I AP - 10

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS
COMPUTER IS STRICTLY PROHIBITED

Oracle University and TechnoLogica use only

b) Has the highest number of employees:

Practice 1-1 (continued) 21) Create an anniversary overview based on the hire date of the employees. Sort the anniversaries in ascending order.11 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 20) Show all the employees who were hired on the day of the week on which the highest number of employees were hired. Oracle Database: SQL Fundamentals I AP .

4) Create a report of employees and their duration of employment. . 1.” SELECT last_name FROM employees WHERE SUBSTR(last_name. 3) For budgeting purposes.1) IN ('J'. SELECT last_name. 1) The HR department needs to find data for all of the clerks who were hired after the year 1997.” “K.10) "New salary" FROM employees WHERE commission_pct IS NULL. hire_date) / 12) YEARS. The employee who has been employed the longest should appear at the top of the list. and SQL functions.12 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. SELECT last_name. Oracle Database: SQL Fundamentals I AP . Show the last name. job. 'M'). basic SQL Developer commands. TRUNC(MOD(MONTHS_BETWEEN(SYSDATE. MONTHS desc.” “L. The report should display those employees who do not get a commission but who have a 10% raise in salary (round off the salaries). COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT * FROM employees WHERE job_id = 'ST_CLERK' AND hire_date > '31-DEC-1997'. Sort the data by salary in descending order.Practice Solutions 1-1 These exercises can be used for extra practice after you have discussed the following topics: basic SQL SELECT statement. Order the report by the duration of their employment. job_id. Show the last names of all employees together with the number of years and the number of completed months that they have been employed. the HR department needs a report on projected raises. 12)) MONTHS FROM employees ORDER BY years DESC. salary. TRUNC(MONTHS_BETWEEN(SYSDATE. SELECT 'The salary of '||last_name||' after a 10% raise is ' || ROUND(salary*1. salary. 2) The HR department needs a report of employees who earn commission. hire_date). commission_pct FROM employees WHERE commission_pct IS NOT NULL ORDER BY salary DESC. 5) Show those employees who have a last name starting with the letters “J.” or “M. and commission of those employees. 'L'. 'K'.

Make sure that the report also includes departments without employees. d. 'No'. Use the DECODE expression in your query. and number of employees for each department.job_id.department_id GROUP BY d. joins. SELECT DISTINCT job_id FROM employees WHERE department_id IN (10.” Create two possible solutions. e.department_id.location_id.location_id. departments d WHERE e. basic SQL Developer commands. location ID. Create a report to display the job IDs for those departments.Practice Solutions 1-1 (continued) 6) Create a report that displays all employees. salary. job title. 8) Find the number of employees who have a last name that ends with the letter “n. a) Enter 1800 for location_id when prompted. -1) = 'n'. Oracle Database: SQL Fundamentals I AP .employee_id) FROM employees e RIGHT OUTER JOIN departments d ON e. e. d. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only These exercises can be used for extra practice after you have discussed the following topics: basic SQL SELECT statement. and indicate with the words Yes or No whether they receive a commission. d. SELECT FROM WHERE --or SELECT FROM WHERE COUNT(*) employees last_name LIKE '%n'. SELECT d.department_id.location_id. d. location. 9) Create a report that shows the name.department_name.department_id = d. 'Yes') commission FROM employees.department_id AND d.department_name. Prompt the user for the location. e.department_id = d.department_name. COUNT(e.13 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. SELECT last_name. 7) Create a report that displays the department name.salary FROM employees e. . SQL functions.location_id = &location_id. name. 20). decode(commission_pct. d. NULL. 10) The HR department needs to find the job titles in departments 10 and 20. SELECT d.last_name. COUNT(*) employees SUBSTR(last_name. and group functions. and salary of those employees who work in a specific location.

SELECT last_name.salary.Practice Solutions 1-1 (continued) 11) Create a report that displays the jobs that are found in the Administration and Executive departments. -3)/1000 FROM employees. count(e. SQL functions.grade_level FROM employees e JOIN employees m ON e. manager name.department_name IN ('Administration'.salary > 15000.salary BETWEEN j.000. 13) Create a report that displays the following for all employees: last name. salary. and salary grade of the manager. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT e. m. basic SQL Developer commands. TRUNC(salary.last_name manager. hire_date FROM employees WHERE TO_CHAR(hire_date.14 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and salary expressed in terms of thousands of dollars. Also display the number of employees for these jobs.manager_id = m.employee_id JOIN job_grades j ON m. Show the job with the highest number of employees first. 12) Show all employees who were hired in the first half of the month (before the 16th of the month). 'Executive') GROUP BY e. Oracle Database: SQL Fundamentals I AP . and subqueries.job_id ORDER BY FREQUENCY DESC.job_id. These exercises can be used for extra practice after you have discussed the following topics: basic SQL SELECT statements.highest_sal AND m. group functions.department_id = d. . 'DD') < 16. salary. j.department_id WHERE d. SELECT e. Thousands 14) Show all employees who have managers with a salary higher than $15. joins. m. SELECT last_name.job_id) FREQUENCY FROM employees e JOIN departments d ON e.last_name.lowest_sal AND j. Show the following data: employee name. manager salary.

99'). COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SELECT . d.department_id RIGHT OUTER JOIN employees e2 ON d.department_id GROUP BY d.department_id.salary.Practice Solutions 1-1 (continued) 15) Show the department number.salary).job_id ORDER BY d.department_id. name. and average salary of all departments.department_name HAVING COUNT(*) < 3. '99999. SELECT department_id. employees. e2. Oracle Database: SQL Fundamentals I AP . Include the department number. and location in the output. 18) Create the following statistical reports for the HR department: Include the department number. e2. MIN(salary) FROM employees GROUP BY department_id HAVING AVG(salary) = (SELECT MAX(AVG(salary)) FROM employees GROUP BY department_id). 16) Create a report to display the department number and lowest salary of the department with the highest average salary.department_name. and jobs of the employees working in each department. d.department_id GROUP BY d.last_name. count(e1.department_name. 17) Create a report that displays the departments where no sales representatives work. e2. department name.salary. and the number of employees working in each department that: a) Employs fewer than three employees: SELECT d. department name. SELECT * FROM departments WHERE department_id NOT IN(SELECT department_id FROM employees WHERE job_id = 'SA_REP' AND department_id IS NOT NULL).job_id FROM departments d RIGHT OUTER JOIN employees e1 ON d.department_name.employee_id) employees. e2.department_id = e1. d.last_name. COUNT(*) FROM departments d JOIN employees e ON d. 'No average' ) avg_sal.department_id. e2. d.department_id. number of employees.department_id = e. d. salaries. e2. NVL(TO_CHAR(AVG(e1.15 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.department_id. together with the names.department_id = e2.

'Month DD') BIRTHDAY FROM employees ORDER BY TO_CHAR(hire_date. SELECT d. e. 20) Show all employees who were hired on the day of the week on which the highest number of employees were hired. AVG(s.department_id. e.department_id GROUP BY d.department_id. e. TO_CHAR(hire_date. 'DAY') day FROM employees WHERE TO_CHAR(hire_date. and the average salary in their department for all employees. Oracle Database: SQL Fundamentals I AP .department_id. 'Day') FROM employees GROUP BY TO_CHAR(hire_date.department_id.department_name HAVING COUNT(*) = (SELECT MIN(COUNT(*)) FROM employees GROUP BY department_id).department_name. department number.department_id = e. SELECT last_name.last_name.department_id. d.department_id GROUP BY d. e. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only c) Has the lowest number of employees: . COUNT(*) FROM departments d JOIN employees e ON d.department_id = s.department_id = e. last name. 'Day') = (SELECT TO_CHAR(hire_date. 19) Create a report that displays the employee number. d. 'Day'))). salary. SELECT last_name. d. e.Practice Solutions 1-1 (continued) b) Has the highest number of employees: SELECT d.department_id GROUP BY e.employee_id.salary. 21) Create an anniversary overview based on the hire date of the employees.employee_id.last_name. e.16 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.department_name. 'Day') HAVING COUNT(*) = (SELECT MAX(COUNT(*)) FROM employees GROUP BY TO_CHAR(hire_date. Sort the anniversaries in ascending order.department_name HAVING COUNT(*) = (SELECT MAX(COUNT(*)) FROM employees GROUP BY department_id).salary.department_id. d.salary) FROM employees e JOIN employees s ON e. TO_CHAR(hire_date. 'DDD'). COUNT(*) FROM departments d JOIN employees e ON d. SELECT e.

If you want to drop the tables. • If you use the buildtab. you can execute the commands in the buildtab.sql script in SQL Developer to create and populate the tables. and delete records in a video store database and generate a report. you build a set of database tables for a video application. start with step 4. update. After you create the tables. you insert. Then you can execute the commands in the buildvid. The following is a diagram of the entities and attributes for the video application: .sql script in SQL Developer. The database contains only the essential tables. you can execute the commands in the dropvid. Oracle Database: SQL Fundamentals I AP .Case Study for RESERVATION #* res date the subject of set up for TITLE #* id * title * description o rating o category o release date available as a copy responsible for MEMBER #* id * last name o first name o address o city o phone * join date TITLE_COPY #* id * status the subject of responsible for made against created for RENTAL #* book date o act ret date o exp ret date Note: If you want to build the tables. All the three SQL scripts are present in the /home/oracle/labs/sql1/labs folder.sql script in SQL Developer. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only In this case study.sql script to build the tables.17 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

18 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practice Solutions 1-1 (continued) If you use the dropvid.sql script to remove the video tables. Oracle University and TechnoLogica use only • • Oracle Database: SQL Fundamentals I AP . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED . start with step 6(b).sql script to build and populate the tables. start with step 1. If you use the buildvid.

Practice 2-1 1) Create the tables based on the following table instance charts. a) Table name: MEMBER MEMBER_ ID Key Type Null/ Unique Default Value PK Data Type Length NN. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Column_ Name . R.U LAST_ NAME FIRST_NAME ADDRESS CITY PHONE JOIN _ DATE NN NN NUMBER VARCHAR2 VARCHAR2 VARCHAR2 VARCHAR2 VARCHAR2 System Date DATE 10 25 25 100 30 15 b) Table name: TITLE Column_ Name TITLE_ID Key Type Null/ Unique Check PK Data Type NUMBER VARCHAR2 VARCHAR2 Length 10 60 400 NN. ACTION. NR VARCHAR2 DRAMA.U TITLE DESCRIPTION NN NN RATING CATEGORY G. COMEDY. NC17. Choose the appropriate data types and be sure to add integrity constraints. DOCUMEN TARY VARCHAR2 4 20 Oracle Database: SQL Fundamentals I AP . SCIFI.19 RELEASE_ DATE DATE THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. PG. CHILD.

FK2 ACT_RET_ DATE System Date TITLE_ ID PK.FK2 System Date + 2 days MEMBER DATE EXP_RET_ DATE MEMBER_I D NUMBER TITLE_ COPY COPY_ ID NUMBER 10 10 TITLE_ COPY TITLE_ID DATE DATE Oracle Database: SQL Fundamentals I AP .U STATUS NN AVAILABLE. RESERVED TITLE TITLE_ID NUMBER NUMBER VARCHAR2 10 10 15 d) Table name: RENTAL Column Name Key Type Default Value FK Ref Table FK Ref Col Data Type Length BOOK_ DATE PK MEMBER_ ID PK.Practice 2-1 (continued) c) Table name: TITLE_COPY FK Ref Table FK Ref Col Data Type Length COPY_ID TITLE_ID PK PK. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Column Name Key Type Null/ Unique Check .U NN. RENTED.20 NUMBER 10 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.FK NN. DESTROYED.FK1 COPY_ ID PK.

U NN MEMBER TITLE MEMBER_ID TITLE_ID NUMBER NUMBER 10 10 DATE 2) Verify that the tables were created properly by checking in the Connections Navigator in SQL Developer.21 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practice 2-1 (continued) Column Name Key Type Null/ Unique FK Ref Table FK Ref Column Data Type Length RES_ DATE MEMBER_ ID TITLE_ ID PK PK. Oracle Database: SQL Fundamentals I AP .U NN. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only e) Table name: RESERVATION .FK1 PK.FK2 NN.

4) Add data to the tables. a) Add movie titles to the TITLE table. do not allow caching of the values. b) Title number for the TITLE table: Start with 92. Remember that single quotation marks in a character field must be specially handled. do not allow caching of the values.sql. Oracle Database: SQL Fundamentals I AP . Write a script to enter the movie information. Use the sequences to uniquely identify each title.Practice 2-1 (continued) 3) Create sequences to uniquely identify each row in the MEMBER table and the TITLE table. a) Member number for the MEMBER table: Start with 101. Verify your additions.22 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Enter the release dates in the DD-MONYYYY format. Name the sequence TITLE_ID_SEQ. Save the statements in a script named lab_apcs_4a. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only c) Verify the existence of the sequences in the Connections Navigator in SQL Developer. Create a script for each set of data to be added. Name the sequence MEMBER_ID_SEQ. .

A six-year-old has doubts about Santa Claus. Yet another installation of science fiction history. a young couple find themselves pitted against a vicious gang. With a little luck and a lot of ingenuity.Title Willie and Christmas Too Alien Again The Glob My Day Off Miracles on Ice Soda Gang Description All of Willie’s friends make a Christmas list for Santa.sql. Be sure to use the sequence to add the member numbers. Rating G Category CHILD Release_date 05-OCT-1995 R SCIFI 19-MAY-1995 NR SCIFI 12-AUG-1995 PG COMEDY 12-JUL-1995 PG DRAMA 12-SEP-1995 NR ACTION 01-JUN-1995 b) Add data to the MEMBER table. but Willie has yet to add his own wish list. After discovering a cache of drugs. Execute commands in the script. Save the insert statements in a script named lab_apcs_4b. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Practice 2-1 (continued) .23 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. First_ Name Carmen Last_Name Velasquez LaDoris Ngao Midori Nagayama Mark Quick-to-See Audry Ropeburn 68 Via Sao Paolo Centrale 6921 King Lagos Way 86 Chu Street Hong Kong Molly Urguhart 3035 Laurier Address 283 King Street 5 Modrany City Seattle Bratislava Quebec Phone 206-8996666 586-3558882 254-8525764 63-559-7777 Join_Date 08-MAR1990 08-MAR1990 17-JUN1991 07-APR-1990 41-559-87 18-JAN1991 18-JAN1991 418-5429988 Oracle Database: SQL Fundamentals I AP . Can the heroine save the planet from the alien life form? A meteor crashes near a small American town and unleashes carnivorous goo in this classic. but she discovers that miracles really do exist. a teenager skips school for a day in New York.

Practice 2-1 (continued) c) Add the following movie copies in the TITLE_COPY table: Note: Have the TITLE_ID numbers available for this exercise. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only 2 .24 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Title Copy_Id Status Title Copy_Id Willie and Christmas Too Alien Again 1 AVAILABLE 1 1 AVAILABLE Willie and Christmas Too Alien Again 2 RENTED The Glob 1 AVAILABLE The Glob 1 My Day Off 1 AVAILABLE My Day Off 1 2 AVAILABLE 2 3 RENTED 3 Miracles on Ice 1 AVAILABLE Miracles on Ice 1 Soda Gang 1 AVAILABLE Soda Gang 1 1 d) Add the following rentals to the RENTAL table: Note: The title number may be different depending on the sequence number. Title_ Id Member_Id 92 Copy_ Id 1 93 101 Book_date 3 days ago Exp_Ret_Date 1 day ago 2 101 1 day ago 1 day from now 95 3 102 2 days ago Today 97 1 106 4 days ago 2 days ago Oracle Database: SQL Fundamentals I AP .

Can the rebels save the humans from the evil empire?” Be sure to add a title copy record for two copies. The movie is “Interstellar Wars. The release date is 07-JUL-77.” which is rated PG and classified as a science fiction movie. The description is “Futuristic interstellar action movie. Order the results by title. Query all rows from the view. who wants to rent “Interstellar Wars.” The other is for Mark Quick-to-See. and its expected return date if rented. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Note: Your results may be different. b) Enter two reservations. the availability of each copy. 6) Make changes to the data in the tables. .25 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. a) Add a new title.” Oracle Database: SQL Fundamentals I AP . who wants to rent “Soda Gang.Practice 2-1 (continued) 5) Create a view named TITLE_AVAIL to show the movie titles. One reservation is for Carmen Velasquez.

Oracle Database: SQL Fundamentals I AP . Total the number of rentals for all customers for the reporting period.sql. Be sure to include the customer name. . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only a) Run the lab_apcs_7a.26 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Note: Your results may be different. 8) Create a report that contains each customer’s history of renting videos. and duration of rentals. to add a PRICE column to the TITLE table to record the purchase price of the video. movie rented. Verify your modifications. Title Willie and Christmas Too Alien Again The Glob My Day Off Miracles on Ice Soda Gang Interstellar Wars Price 25 35 35 35 30 35 29 b) Create a script named lab_apcs_7b. dates of the rental.sql script located in the /home/oracle/labs/sql1/labs folder. Run the commands in the script. Save the commands that generate the report in a script file named lab_apcs_8. Note: Have the TITLE_ID numbers available for this exercise.Practice 2-1 (continued) 7) Make a modification to one of the tables.sql that contains update statements that update each video with a price according to the preceding list.

join_date DATE DEFAULT SYSDATE CONSTRAINT member_join_date_nn NOT NULL).'RENTED'. first_name VARCHAR2(25). address VARCHAR2(100). rating VARCHAR2(4) CONSTRAINT title_rating_ck CHECK (rating IN ('G'. c) Table name: TITLE_COPY CREATE TABLE title_copy (copy_id NUMBER(10). category VARCHAR2(20) CONSTRAINT title_category_ck CHECK (category IN ('DRAMA'. 'COMEDY'. phone VARCHAR2(15). title_id)). Oracle Database: SQL Fundamentals I AP . 'CHILD'.Practice Solutions 2-1 1) Create the tables based on the following table instance charts. last_name VARCHAR2(25) CONSTRAINT member_last_name_nn NOT NULL. release_date DATE). status VARCHAR2(15) CONSTRAINT title_copy_status_nn NOT NULL CONSTRAINT title_copy_status_ck CHECK (status IN ('AVAILABLE'. b) Table name: TITLE CREATE TABLE title (title_id NUMBER(10) CONSTRAINT title_title_id_pk PRIMARY KEY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only a) Table name: MEMBER . 'PG'. 'ACTION'. title_id NUMBER(10) CONSTRAINT title_copy_title_if_fk REFERENCES title(title_id). CREATE TABLE member (member_id NUMBER(10) CONSTRAINT member_member_id_pk PRIMARY KEY. 'DOCUMENTARY')). Choose the appropriate data types and be sure to add integrity constraints. city VARCHAR2(30). 'R'. description VARCHAR2(400) CONSTRAINT title_description_nn NOT NULL. 'SCIFI'. CONSTRAINT title_copy_copy_id_title_id_pk PRIMARY KEY (copy_id. 'DESTROYED'.27 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. title VARCHAR2(60) CONSTRAINT title_title_nn NOT NULL. 'RESERVED')). 'NC17'. 'NR')).

CREATE SEQUENCE title_id_seq START WITH 92 NOCACHE. Name the sequence TITLE_ID_SEQ. member_id NUMBER(10) CONSTRAINT reservation_member_id REFERENCES member(member_id). CONSTRAINT reservation_resdate_mem_tit_pk PRIMARY KEY (res_date. act_ret_date DATE. title_id NUMBER(10). e) Table name: RESERVATION CREATE TABLE reservation (res_date DATE. do not allow caching of the values. CONSTRAINT rental_copy_id_title_id_fk FOREIGN KEY (copy_id. CONSTRAINT rental_book_date_copy_title_pk PRIMARY KEY (book_date. 2) Verify that the tables were created properly by checking in the Connections Navigator in SQL Developer. a) In the Connections Navigator.title_id). expand Connections > myconnection > Tables. exp_ret_date DATE DEFAULT SYSDATE + 2.28 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. title_id) REFERENCES title_copy(copy_id. Oracle Database: SQL Fundamentals I AP . title_id)). title_id)). title_id NUMBER(10) CONSTRAINT reservation_title_id REFERENCES title(title_id). Name the sequence MEMBER_ID_SEQ. do not allow caching of the values. b) Title number for the TITLE table: Start with 92. copy_id. a) Member number for the MEMBER table: Start with 101. 3) Create sequences to uniquely identify each row in the MEMBER table and the TITLE table. CREATE SEQUENCE member_id_seq START WITH 101 NOCACHE. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only d) Table name: RENTAL . member_id. member_id.Practice Solutions 2-1 (continued) CREATE TABLE rental (book_date DATE DEFAULT SYSDATE. copy_id NUMBER(10). member_id NUMBER(10) CONSTRAINT rental_member_id_fk REFERENCES member(member_id).

TO_DATE('12-SEP-1995'. 'Yet another installment of science fiction history. TO_DATE( '12-AUG-1995'.NEXTVAL. title. TO_DATE( '12-JUL-1995'. 'With a little luck and a lot ingenuity. title. description. 'G'. 'A sixyear-old has doubts about Santa Claus. Can the heroine save the planet from the alien life form?'. title.NEXTVAL. 'PG'. description. 'Miracles on Ice'. category. Verify your additions.29 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. i) In the Connections Navigator. 'PG'.'. category. 'SCIFI'.NEXTVAL. TO_DATE('05-OCT-1995'. 'COMEDY'.Practice Solutions 2-1 (continued) c) Verify the existence of the sequences in the Connections Navigator in SQL Developer. category. 'DRAMA'. rating. 'R'. description. Create a script for each set of data to be added. but she discovers that miracles really do exist. release_date) VALUES (title_id_seq.'.'DD-MON-YYYY')) / INSERT INTO title(title_id. 'My Day Off'. a teenager skips school for a day in New York.'DD-MON-YYYY')) / INSERT INTO title(title_id.sql. TO_DATE( '19-MAY-1995'. release_date) VALUES (title_id_seq. Save the statements in a script named lab_apcs_4a.'. category. description. rating. Use the sequences to uniquely identify each title. release_date) VALUES (title_id_seq. Enter the release dates in the DD-MONYYYY format. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only a) Add movie titles to the TITLE table. expand Sequences. title. 'NR'.'.'DD-MON-YYYY')) / INSERT INTO title(title_id .NEXTVAL. INSERT INTO title(title_id. 'Alien Again'. Write a script to enter the movie information.NEXTVAL. rating. assuming that the myconnection node is expanded. 'Willie and Christmas Too'.'DD-MON-YYYY')) / Oracle Database: SQL Fundamentals I AP . description. 'SCIFI'. release_date) VALUES (title_id_seq. 'CHILD'. release_date) VALUES (title_id_seq. 'A meteor crashes near a small American town and unleashes carnivorous goo in this classic. . title.'DD-MON-YYYY')) / INSERT INTO title(title_id. category. rating. Remember that single quotation marks in a character field must be specially handled. 4) Add data to the tables. but Willie has yet to add his own wish list. 'All of Willie''s friends make a Christmas list for Santa. 'The Glob'. rating.

'Sao Paolo'. first_name.Practice Solutions 2-1 (continued) b) Add data to the MEMBER table. 'Midori'. join_date) VALUES (member_id_seq. '206-899-6666'. first_name. TO_DATE('08-MAR-1990'. last_name. '63-559-7777'. 'Carmen'.'. TO_DATE('07APR-1990'.'DD-MON-YYYY')) / COMMIT / SELECT title FROM title. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only INSERT INTO title(title_id. Be sure to use the sequence to add the member numbers. 'Mark'. a young couple find themselves pitted against a vicious gang. address. address. 'Lagos'. '283 King Street'. 'NR'. last_name.NEXTVAL. 'DD-MM-YYYY')) / INSERT INTO member(member_id. Execute the commands in the script.30 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. TO_DATE('17-JUN-1991'.NEXTVAL. 'LaDoris'. description. last_name. 'Seattle'. '5 Modrany'. first_name. address. join_date) VALUES (member_id_seq. 'Nagayama'. '254-852-5764'.sql. city. 'ACTION'. rating. 'Velasquez'. . phone. 'Quick-to-See'. TO_DATE('01JUN-1995'. '586-355-8882'. release_date) VALUES (title_id_seq. join_date) VALUES (member_id_seq. 'Soda Gang'.NEXTVAL. city. 'Ngao'. last_name. SET VERIFY OFF INSERT INTO member(member_id. title. join_date) VALUES (member_id_seq. phone. city.NEXTVAL. 'DD-MM-YYYY')) / INSERT INTO member(member_id.NEXTVAL. TO_DATE('08-MAR-1990'. '68 Via Centrale'. first_name. city. Place the insert statements in a script named lab_apcs_4b. 'DD-MM-YYYY')) / INSERT INTO member(member_id. address. phone. '6921 King Way'. category. phone. 'After discovering a cache of drugs. 'DD-MM-YYYY')) / Oracle Database: SQL Fundamentals I AP . 'Bratislava'.

NEXTVAL. 'Urguhart'. first_name. title_id. 'DD-MM-YYYY')).status) (1. status) (2. TO_DATE('18-JAN-1991'. 'AVAILABLE') Oracle Database: SQL Fundamentals I AP . 'Ropeburn'. 93.NEXTVAL. 'RENTED') INTO title_copy(copy_id. 95. '86 Chu Street'. status) (1. title_id. title_id. '3035 Laurier'. 'AVAILABLE') INTO title_copy(copy_id. 95. 'AVAILABLE') INTO title_copy(copy_id. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only INSERT INTO member(member_id. 'AVAILABLE') INTO title_copy(copy_id. title_id. 'Quebec'.status) (3. last_name. join_date) VALUES (member_id_seq. 96. INSERT VALUES / INSERT VALUES / INSERT VALUES / INSERT VALUES / INSERT VALUES / INSERT VALUES / INSERT VALUES / INSERT VALUES / INSERT VALUES / INTO title_copy(copy_id. first_name. status) (1. phone.Practice Solutions 2-1 (continued) INSERT INTO member(member_id. 'DD-MM-YYYY')) / . 'AVAILABLE') INTO title_copy(copy_id.status) (1. 97. status) (1. title_id. address. 92. 'RENTED') INTO title_copy(copy_id. 94. '418-542-9988'. 'Hong Kong'. 'AVAILABLE') INTO title_copy(copy_id.31 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. '41-559-87'. title_id. / COMMIT SET VERIFY ON c) Add the following movie copies in the TITLE_COPY table: Note: Have the TITLE_ID numbers available for this exercise.status) (2. city. title_id. title_id. 95. 'AVAILABLE') INTO title_copy(copy_id. status) (1. title_id. city. 'Audry'. phone. 93. join_date) VALUES (member_id_seq. TO_DATE('18JAN-1991'. last_name. 'Molly'. address.

book_date.exp_ret_date FROM title t JOIN title_copy c ON t. the availability of each copy. sysdate-2) / INSERT INTO rental(title_id.act_ret_date) VALUES (97. 102. book_date. member_id.status.copy_id. 106. member_id.copy_id = r. book_date. SELECT * FROM title_avail ORDER BY title. sysdate. act_ret_date) VALUES (93. CREATE VIEW title_avail AS SELECT t. 3. 1. exp_ret_date. member_id.32 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Practice Solutions 2-1 (continued) d) Add the following rentals to the RENTAL table: INSERT INTO rental(title_id. act_ret_date) VALUES (92. Query all rows from the view. 101.title_id. . copy_id. NULL) / INSERT INTO rental(title_id. Order the results by title.title_id FULL OUTER JOIN rental r ON c.title_id = c. act_ret_date) VALUES (95. sysdate-1. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Note: The title number may be different depending on the sequence number. c. copy_id. book_date. c. copy_id.title. r. Oracle Database: SQL Fundamentals I AP . copy_id. 1. 101.title_id = r. member_id. exp_ret_date. NULL) / INSERT INTO rental(title_id. sysdate-2) / COMMIT / 5) Create a view named TITLE_AVAIL to show the movie titles. sysdate-3. sysdate-2.copy_id AND c. sysdate-4. 2. copy_id. exp_ret_date. sysdate-2. Note: Your results may be different. and its expected return date if rented. sysdate-1. exp_ret_date. sysdate-1.

description. The description is “Futuristic interstellar action movie. ALTER TABLE title ADD (price NUMBER(8. title_id) (SYSDATE.33 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. member_id. 98) INTO reservation (res_date.Practice Solutions 2-1 (continued) 6) Make changes to data in the tables. 97) 7) Make a modification to one of the tables. INSERT INTO title(title_id. release_date) VALUES (title_id_seq. 98.” The other is for Mark Quick-to-See. a) Run the lab_apcs_7a. category. to add a PRICE column to the TITLE table to record the purchase price of the video. 'SCIFI'. One reservation is for Carmen Velasquez. title. title_id. The release date is 07-JUL-77. 'AVAILABLE') / b) Enter two reservations. DESCRIBE title Oracle Database: SQL Fundamentals I AP . Can the rebels save the humans from the evil empire?” Be sure to add a title copy record for two copies. title_id) (SYSDATE.2)). status) VALUES (1. 98. member_id. rating.sql script located in the /home/oracle/labs/sql1/labs folder. Verify your modifications. . title_id. Can the rebels save the humans from the evil empire?'.” INSERT VALUES / INSERT VALUES / INTO reservation (res_date. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only a) Add a new title. The movie is “Interstellar Wars.” which is rated PG and classified as a science fiction movie.NEXTVAL. 'Interstellar Wars'. who wants to rent “Interstellar Wars. 'Futuristic interstellar action movie. 101. 104. 'PG'. '07-JUL-77') / INSERT INTO title_copy (copy_id. 'AVAILABLE') / INSERT INTO title_copy (copy_id. status) VALUES (2. who wants to rent “Soda Gang.

r.34 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only SET ECHO OFF SET VERIFY OFF UPDATE title SET price = &price WHERE title_id = &title_id. SELECT m.book_date. Note: Your results may be different.title_id = t. and duration of rentals. Total the number of rentals for all customers for the reporting period.sql that contains update statements that update each video with a price according to the list provided.act_ret_date . SET VERIFY OFF SET ECHO OFF .first_name||' '||m. t. Be sure to include the customer name. Oracle Database: SQL Fundamentals I AP .sql.Practice Solutions 2-1 (continued) b) Create a script named lab_apcs_7b. Note: Have the TITLE_ID numbers available for this exercise. Run the commands in the script. dates of the rental.last_name MEMBER. 8) Create a report that contains each customer’s history of renting videos. Save the commands that generate the report in a script file named lab_apcs_8.title.book_date DURATION FROM member m JOIN rental r ON r.title_id ORDER BY member.member_id JOIN title t ON r.r. r.member_id = m. movie rented.

Oracle and/or its affiliates.Copyright © 2010. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Table Descriptions . All rights reserved. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

and the department are recorded. and the country code. .2 Oracle University and TechnoLogica use only The Oracle Database sample schemas portray a sample company that operates worldwide to fill orders for several different products. Each job has an identification code. state or province. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B . The company also tracks information about jobs within the organization. so it tracks the locations of its warehouses and departments. salary. and a minimum and maximum salary range for the job. When an employee resigns. and manager. Each department is associated with one location. city. demonstrations. the emphasis of the examples. job identification code. each employee has an identification number. Each employee is assigned to a department. postal code. currency name. you have access to the objects in all the schemas. job title. The company has three divisions: • Human Resources: Tracks information about the employees and facilities • Order Entry: Tracks product inventories and sales through various channels • Sales History: Tracks business statistics to facilitate business decisions Each of these divisions is represented by a schema. Some employees earn commissions in addition to their salary. and practices is on the Human Resources (HR) schema. Human Resources (HR) This is the schema that is used in this course. and each location has a full address that includes the street name. In places where the departments and warehouses are located. The sample company is regionally diverse. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. currency symbol.Schema Description Overall Description All scripts necessary to create the sample schemas reside in the $ORACLE_HOME/demo/schema/ folder. However. the company records details such as the country name. and the region where the country is located geographically. and each department is identified either by a unique department number or a short name. In this course. Some employees have been with the company for a long time and have held different positions within the company. email address. In the Human Resource (HR) records. the duration the employee was working for. the job identification number.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B .HR Entity Relationship Diagram DEPARTMENTS department_id department_name manager_id location_id JOB_HISTORY employee_id start_date end_date job_id department_id JOBS job_id job_title min_salary max_salary LOCATIONS location_id street_address postal_code city state_province country_id EMPLOYEES employee_id first_name last_name email phone_number hire_date job_id salary commission_pct manager_id department_id COUNTRIES country_id country_name region_id REGIONS region_id region_name THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.3 Oracle University and TechnoLogica use only HR .

Human Resources (HR) Table Descriptions DESCRIBE countries Oracle University and TechnoLogica use only SELECT * FROM countries. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B .4 . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

5 .Human Resources (HR) Table Descriptions (continued) DESCRIBE departments Oracle University and TechnoLogica use only SELECT * FROM departments. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B .

. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.SELECT * FROM employees. . Oracle Database: SQL Fundamentals I B .6 Oracle University and TechnoLogica use only Human Resources (HR) Table Descriptions (continued) DESCRIBE employees .

7 . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B .Human Resources (HR) Table Descriptions (continued) DESCRIBE job_history Oracle University and TechnoLogica use only SELECT * FROM job_history THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B .8 .Human Resources (HR) Table Descriptions (continued) DESCRIBE jobs Oracle University and TechnoLogica use only SELECT * FROM jobs THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B .9 .Human Resources (HR) Table Descriptions (continued) DESCRIBE locations Oracle University and TechnoLogica use only SELECT * FROM locations THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

10 . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I B .Human Resources (HR) Table Descriptions (continued) DESCRIBE regions Oracle University and TechnoLogica use only SELECT * FROM regions THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

All rights reserved.Copyright © 2010. Oracle and/or its affiliates. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Using SQL Developer .

All rights reserved. Oracle and/or its affiliates.2 Oracle University and TechnoLogica use only Objectives . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you should be able to do the following: • List the key features of Oracle SQL Developer • Identify the menu items of Oracle SQL Developer • Create a database connection • Manage database objects • Use SQL Worksheet • Save and run SQL scripts • Create and save reports Copyright © 2010. You learn how to use SQL Developer for your database development tasks. you are introduced to the graphical tool called SQL Developer. Objectives In this appendix.After completing this appendix. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . You learn how to use SQL Worksheet to execute SQL statements and SQL scripts.

test SQL statements. Microsoft SQL Server. simplifies the following tasks: • Browsing and managing database objects • Executing SQL statements and scripts • Editing and debugging PL/SQL statements • Creating reports You can connect to any target Oracle database schema by using standard Oracle database authentication. SQL Developer includes support for Oracle Application Express 3. You can also connect to schemas for selected third-party (non-Oracle) databases. The SQL Developer 1.1 (Oracle THESE APEX). and Microsoft Access. you can easily create and debug stored procedures. All rights reserved. which is the visual tool for database development. eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you can perform operations on objects in the database.3 Oracle University and TechnoLogica use only • .What Is Oracle SQL Developer? • Oracle SQL Developer is a graphical tool that enhances productivity and simplifies database development tasks. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . and to migrate from these databases to Oracle. Oracle and/or its affiliates. and view optimizer plans. SQL Developer. SQL Developer Copyright © 2010. such as MySQL. With just a few clicks. When connected.0. Additionally. You can connect to any target Oracle database schema by using standard Oracle database authentication. What Is Oracle SQL Developer? Oracle SQL Developer is a free graphical tool designed to improve your productivity and simplify the development of everyday database tasks.2 release tightly integrates with Developer Migration Workbench that provides users with a single point to browse database objects and data in third-party databases. and view metadata and data in these databases.

All rights reserved.oracle.oracle. no Oracle Home is required. see the Web site at: http://download. and therefore. Note For Oracle Database versions before Oracle Database 11g Release 2. The tool runs on Windows.2.5 is freely downloadable from the following link: http://www. and Mac OS X platforms Enables default connectivity using the JDBC Thin driver Connects to Oracle Database version 9.html. users can connect to Oracle Databases 9.html Copyright © 2010. Therefore.5 is shipped along with Oracle Database 11g Release 2. it is a cross-platform tool.oracle.1 and later Freely downloadable from the following link: – http://www.0.htm THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you will have to download and install SQL Developer. With SQL Developer.com/docs/cd/E12151_01/index. and Mac operating system (OS) X platforms. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . Linux.com/technology/products/database/ sql_developer/index. and all Oracle database editions including Express Edition. Specifications of SQL Developer Oracle SQL Developer 1. Oracle and/or its affiliates. SQL Developer 1. For instructions on how to install SQL Developer.4 Oracle University and TechnoLogica use only Specifications of SQL Developer . SQL Developer is developed in Java leveraging the Oracle JDeveloper integrated development environment (IDE).1 and later. The default connectivity to the database is through the Java Database Connectivity (JDBC) Thin driver.0. Linux.com/technology/products/database/sql_developer/index.• • • • • • Shipped along with Oracle Database 11g Release 2 Developed in Java Supports Windows. SQL Developer does not require an installer and you need to simply unzip the downloaded file.2.

General Navigation and Use SQL Developer uses the left side for navigation to find and select objects. Oracle and/or its affiliates. You can customize many aspects of the appearance and behavior of SQL Developer by setting preferences. you can browse database objects and users to which you have access.5 Interface .5 interface contains three main navigation tabs. • Files tab: Identified by the Files folder icon. SQL Developer 1. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.5 Oracle University and TechnoLogica use only SQL Developer 1. this tab enables you to access files from your local machine without having to use the File > Open menu. Note: You need to define at least one connection to be able to connect to a database schema and issue SQL queries or run procedures/functions.You must define a connection to start using SQL Developer for running SQL queries on a database schema. Copyright © 2010. All rights reserved. and the right side to display information about selected objects.5 Interface The SQL Developer 1. • Reports tab: Identified by the Reports icon. from left to right: • Connections tab: By using this tab. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . this tab enables you to run predefined reports or create and add your own reports.

plus entries for features specific to SQL Developer: • View: Contains options that affect what is displayed in the SQL Developer interface • Navigate: Contains options for navigating to panes and for executing subprograms • Run: Contains the Run File and Execution Profile options that are relevant when a function or procedure is selected. Preferences. and SQL Worksheet Note: The Run menu also contains options that are relevant when a function or procedure is selected for debugging.6 Oracle University and TechnoLogica use only SQL Developer 1.THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. • Migration: Contains options related to migrating third-party databases to Oracle • Tools: Invokes SQL Developer tools such as SQL*Plus.5 Interface (continued) Menus The following menus contain standard entries. • Source: Contains options for use when you edit functions and procedures • Versioning: Provides integrated support for the following versioning and source control systems: CVS (Concurrent Versions System) and Subversion. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . These are the same options that are found in the Debug menu in version 1. .2. and also debugging options.

but it can also be in the directory specified by the TNS_ADMIN environment variable or registry value. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . To use SQL Developer. Oracle and/or its affiliates.ora file exists. but its connections are not being used by SQL Developer.ora file on your system.ora file on your system. created. You can create and test connections for multiple databases and for multiple schemas.Creating a Database Connection • • You must have at least one database connection to use SQL Developer. Creating a Database Connection A connection is a SQL Developer object that specifies the necessary information for connecting to a specific database as a specific user of that database.7 Oracle University and TechnoLogica use only – Multiple databases – Multiple schemas . You can create additional connections as different users to the same database or to connect to the different databases. • You can export connections to an Extensible Markup Language (XML) file. or imported. All rights reserved. • Copyright © 2010.ora file is located in the $ORACLE_HOME/network/admin directory. You can export connections to an XML file so that you can reuse it. if the tnsnames. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Note: On Windows. By default. When you start SQL Developer and display the Database Connections dialog box. the tnsnames. which may be existing. SQL Developer automatically imports any connections defined in the tnsnames. you must have at least one database connection. You can create and test connections for: • SQL Developer automatically imports any connections defined in the tnsnames. Each additional database connection created is listed in the Connections Navigator hierarchy. define TNS_ADMIN as a system environment variable.

Advanced: You can define a custom Java Database Connectivity (JDBC) URL to connect to the database. you can select either default or SYSDBA. Enter the username and password of the schema that you want to connect to.ora file. perform the following steps: 1. Creating a Database Connection (continued) To create a database connection. TNS: You can select any one of the database aliases imported from the tnsnames. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . right-click Connections and select New Connection.Creating a Database Connection 2 3 Copyright © 2010. which is a component of Oracle Identity Management. LDAP: You can look up database services in Oracle Internet Directory. You can also choose to enter the Service name directly if you use a remote database connection. Port is already set to 1521. (You choose SYSDBA for the sys user or any user with database administrator privileges. Oracle and/or its affiliates. In the New/Select Database Connection window. c) Click Test to ensure that the connection has been set correctly. All rights reserved. a) From the Role drop-down list. enter the connection name. 2. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. enter host name and SID for the database you want to connect to.) b) You can select the connection type as: Basic: In this type.8 Oracle University and TechnoLogica use only 1 . d) Click Connect. On the Connections tabbed page.

9 . you are not prompted for the password. You can expand the connection to view the database objects and view object definitions—for example. So. The connection gets added in the Connections Navigator. these connections are read-only connections that enable you to browse objects and data in that data source. However. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . after you close the SQL Developer connection and open it again. statistics. dependencies. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. details. the password is saved to an XML file. you can define connections to non-Oracle data sources using the Access. Note: From the same New/Select Database Connection window. and SQL Server tabs. MySQL.Oracle University and TechnoLogica use only Creating a Database Connection (continued) If you select the Save Password check box. 3. and so on.

Indexes. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . 2. You can see the definition of the objects broken into tabs of information that is pulled out of the data dictionary. and commit these changes to the database.10 Oracle University and TechnoLogica use only Use the Connections Navigator to: • Browse through many objects in a database schema • Review the definitions of objects at a glance . constraints. if you select a table in the Navigator. You can customize many aspects of the appearance of SQL Developer by setting preferences. For example. Procedures. Using the Data tab. triggers. Expand the Connections node in the Connections Navigator. Packages. Views. SQL Developer uses the left side for navigation to find and select objects. grants. If you want to see the definition of the EMPLOYEES table as shown in the slide. Click EMPLOYEES. the Columns tab is selected. Expand Tables. All rights reserved. perform the following steps: 1. you can use the Connections Navigator to browse through many objects in a database schema including Tables. Browsing Database Objects After you create a database connection. and Types. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you can view the table data and also enter new rows. and so on are displayed on an easy-to-read tabbed page. Triggers. It shows the column description of the table. the details about columns. statistics. and the right side to display information about the selected objects. 3.Browsing Database Objects Copyright © 2010. By default. Oracle and/or its affiliates. update data.

The result of the command is a display of column names and data types as well as an indication if a column must contain data. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you can also display the structure of a table using the DESCRIBE command. All rights reserved. Oracle and/or its affiliates. Displaying the Table Structure In SQL Developer. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C .11 Oracle University and TechnoLogica use only Use the DESCRIBE command to display the structure of a table: .Displaying the Table Structure Copyright © 2010.

Oracle and/or its affiliates. double-click a file name to display its contents in the SQL worksheet area. All rights reserved. Browsing Database Objects You can use the File Navigator to browse and open system files. click the Files tab. • To view the contents of a file.12 Oracle University and TechnoLogica use only Use the File Navigator to explore the file system and open system files. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . . • To view the files navigator. or select View > Files.Browsing Files Copyright © 2010. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

As new objects are created or existing objects are edited. Copyright © 2010. When created. you can create objects using the context menus. Alternatively. each reflecting a logical grouping of properties for that type of object. you can edit the objects using an edit dialog box or one of the many context-sensitive menus. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Creating a Schema Object SQL Developer supports the creation of any schema object by executing a SQL statement in SQL Worksheet. An Export DDL option is available if you want to create the full DDL for one or more objects in the schema. The dialog boxes to create and edit database objects have multiple tabs. The slide shows how to create a table using the context menu. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . Oracle and/or its affiliates. View the data definition language (DDL) for adjustments such as creating a new object or editing an existing schema object.Creating a Schema Object • SQL Developer supports the creation of any schema object by: • • Edit the objects by using an edit dialog box or one of the many context-sensitive menus. right-click Tables and select New Table. All rights reserved. the DDL for those adjustments is available for review. To open a dialog box for creating a new table.13 Oracle University and TechnoLogica use only – Executing a SQL statement in SQL Worksheet – Using the context menu .

The example in the slide shows how to create the DEPENDENTS table by selecting the Advanced check box. 2. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Creating a New Table: Example In the Create Table dialog box. if you do not select the Advanced check box. To create a new table.14 Oracle University and TechnoLogica use only Creating a New Table: Example . right-click Tables. Sometimes. In the Create Table dialog box. to do so. Specify the column information. If you select the Advanced check box. you may want to edit the table that you have created. Oracle and/or its affiliates. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . 3. 5. in which you can specify an extended set of features while you create the table. the Create Table dialog box changes to one with multiple options.Copyright © 2010. right-click the table in the Connections Navigator and select Edit. select Advanced. you should also specify a primary key by using the Primary Key tab in the dialog box. All rights reserved. you can create a table quickly by specifying columns and some frequently used features. perform the following steps: 1. In the Connections Navigator. Although it is not required. Click OK. 4. Select Create TABLE.

a SQL Worksheet window for that connection automatically opens.15 Oracle University and TechnoLogica use only • . You can use the SQL Worksheet to enter and execute SQL. All rights reserved. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . Or. You can specify actions that can be processed by the database connection associated with the worksheet. SQL*Plus statements that are not supported by the SQL Worksheet are ignored and not passed to the database. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. such as: • Creating a table • Inserting data • Creating and editing a trigger • Selecting data from a table • Saving the selected data to a file You can display a SQL Worksheet by using one of the following: • Select Tools > SQL Worksheet. Oracle and/or its affiliates. Using the SQL Worksheet When you connect to a database. • Click the Open SQL Worksheet icon. Select SQL Worksheet from the Tools menu. PL/SQL. and SQL *Plus statements. Specify any actions that can be processed by the database connection associated with the worksheet. The SQL Worksheet supports SQL*Plus statements to a certain extent. click the Open SQL Worksheet icon. PL/SQL. and SQL*Plus statements. Copyright © 2010.Using the SQL Worksheet • Use the SQL Worksheet to enter and execute SQL.

You can use substitution variables in the SQL statements. Execute Statement: Executes the statement where the cursor is located in the Enter SQL Statement box. but not bind variables. Autotrace: Generates trace information for the statement 9. Execute Explain Plan: Generates the execution plan.Using the SQL Worksheet 1 4 3 6 5 8 7 9 Copyright © 2010. but not substitution variables. All rights reserved. 3.16 Oracle University and TechnoLogica use only 2 . Rollback: Discards any changes to the database. which you can see by clicking the Explain tab 8. running a script. Using the SQL Worksheet (continued) You may want to use the shortcut keys or icons to perform certain tasks such as executing a SQL statement. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . Commit: Writes any changes to the database and ends the transaction 4. without writing them to the database. Cancel: Stops the execution of any statements currently being executed 6. You can use bind variables in the SQL statements. You can use the SQL Worksheet toolbar that contains icons to perform the following tasks: 1. 2. Oracle and/or its affiliates. and viewing the history of SQL statements that you have executed. SQL History: Displays a dialog box with information about SQL statements that you have executed 7. Run Script: Executes all statements in the Enter SQL Statement box by using the Script Runner. Clear: Erases the statement or statements in the Enter SQL Statement box THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and ends the transaction 5.

Copyright © 2010. Through the SQL Worksheet. a SQL Worksheet window for that connection automatically opens. You can use the SQL Worksheet to enter and execute SQL. All rights reserved. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . You can display a SQL Worksheet by using any of the following options: • Select Tools > SQL Worksheet. .17 Oracle University and TechnoLogica use only Enter SQL statements. Using the SQL Worksheet (continued) When you connect to a database. Oracle and/or its affiliates. Commands not supported by the SQL Worksheet are ignored and are not sent to the Oracle database. SQL*Plus commands used in the SQL Developer have to be interpreted by the SQL Worksheet before being passed to the database. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. • Click the Open SQL Worksheet icon. PL/SQL. All SQL and PL/SQL commands are supported as they are passed directly from the SQL Worksheet to the Oracle database. The SQL Worksheet currently supports a number of SQL*Plus commands. you can execute SQL statements and some of the SQL*Plus commands.Using the SQL Worksheet Results are shown here. and SQL*Plus statements.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . F5 F5 F9 Copyright © 2010. Oracle and/or its affiliates. All rights reserved.Executing SQL Statements Use the Enter SQL Statement box to enter single or multiple SQL statements. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Executing SQL Statements The example in the slide shows the difference in output for the same query when the [F9] key or Execute Statement is used versus the output when [F5] or Run Script is used.18 Oracle University and TechnoLogica use only F9 .

perform the following steps: 1. enter a file name. the Enter SQL Statement window displays a tabbed page of your file contents. To save the contents of the Enter SQL Statement box. Click the Save icon or use the File > Save menu item. Saving SQL Scripts You can save your SQL statements from the SQL Worksheet into a text file. Click Save. Each file displays as a tabbed page. 2 Identify a location. 2. enter a value in the “Select default path to look for scripts” field. enter a file name and the location where you want the file saved. Under Tools > Preferences > Database > Worksheet Parameters. After you save the contents to a file. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.19 Oracle University and TechnoLogica use only Click the Save icon to save your SQL statement to a file. 1 . All rights reserved. and click Save. 3. In the Save dialog box. Script Pathing You can select a default path to look for scripts and to save scripts.Saving SQL Scripts 3 The contents of the saved file are visible and editable in your SQL Worksheet window. Copyright © 2010. You can have multiple files open at the same time. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . Oracle and/or its affiliates.

. select (or navigate to) the script file that you want to open. Oracle and/or its affiliates. 4. select (or navigate to) the script file that you want to open.20 Oracle University and TechnoLogica use only 1. 4. In the files navigator. The Open dialog box is displayed. Select the connection you want to use for the script execution. All rights reserved. Double-click to open. If you have not selected a connection from the connection drop-down list. 1 Use the Files tab to locate the script file that you want to open. click the Run Script (F5) icon on the SQL Worksheet toolbar. Select File > Open. Select a connection from the connection drop-down list. perform the following steps: 1. 3. or 3 • Run Script (F5) 2 Select a connection from the drop-down list. To run the code. 5. 3. To run the code. Copyright © 2010. Click Open. The code of the script file is displayed in the SQL Worksheet area. 2. a connection dialog box will appear. click either: • Execute Script (F9). a connection dialog box will appear. Double-click the script to display the code in the SQL Worksheet. Executing Saved Script Files: Method 1 To open a script file and display the code in the SQL Worksheet area. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C .Executing Saved Script Files: Method 1 2. Select a connection from the connection drop-down list. If you have not selected a connection from the connection drop-down list. Select the connection you want to use for the script execution THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. In the Open dialog box. click the Run Script (F5) icon on the SQL Worksheet toolbar. 2. The code of the script file is displayed in the SQL Worksheet area. you can also do the following: 1. To run the code. Alternatively.

and name of the file you want to run. 2.Executing Saved Script Files: Method 2 The output from the script is displayed on the Script Output tabbed page. All rights reserved. The results from running the file are displayed on the Script Output tabbed page. followed by the location. in the Enter SQL Statement window. Executing Saved Script Files: Method 2 To run a saved SQL script. The File Save dialog box appears and you can identify a name and location for your file. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Use the @ command. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . . perform the following steps: 1. You can also save the script output by clicking the Save icon on the Script Output tabbed page. Click the Run Script icon. Oracle and/or its affiliates. and click the Run Script icon. Copyright © 2010.21 Oracle University and TechnoLogica use only Use the @ command followed by the location and name of the file that you want to execute.

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. After formatting.Formatting the SQL Code After formatting Copyright © 2010. before formatting. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . SQL Developer has a feature for formatting SQL code. the SQL code is beautified with the keywords capitalized and the statement properly indented. All rights reserved. right-click in the statement area. In the example in the slide.22 Oracle University and TechnoLogica use only Before formatting . the SQL code has the keywords not capitalized and the statement not properly indented. spacing. and select Format SQL. Formatting the SQL Code You may want to format the indentation. Oracle and/or its affiliates. To format the SQL code. and line separation of the SQL code. capitalization.

SQL Developer has the feature called Snippets.Using Snippets Snippets are code fragments that may be just syntax or examples. and miscellaneous PL/SQL programming techniques. Optimizer hints. You can drag snippets into the Editor window. All rights reserved. You can use the drop-down list to select a group. you can select the functions category that you want. To display Snippets. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Snippets are code fragments such as SQL functions. so that you can display the Snippets window if it becomes hidden. A Snippets button is placed in the right window margin. Using Snippets You may want to use certain code fragments when you use the SQL Worksheet or create or edit a PL/SQL function or procedure. Oracle and/or its affiliates. From the drop-down list. it shows the Snippets window. select View > Snippets.23 Oracle University and TechnoLogica use only When you place your cursor here. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . . The Snippets window is displayed at the right. Copyright © 2010.

drag the snippet from the Snippets window to the desired place in your code. Using Snippets: Example To insert a Snippet into your code in a SQL Worksheet or in a PL/SQL function or procedure. place the cursor over the function name. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. last_name) FROM employees. Then you can edit the syntax so that the SQL function is valid in the current context. Then the CONCAT function syntax is edited and the rest of the statement is added as in the following: SELECT CONCAT(first_name. To see a brief description of a SQL function in a tool tip.Using Snippets: Example Editing the snippet Copyright © 2010. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C .24 Oracle University and TechnoLogica use only Inserting a snippet . The example in the slide shows that CONCAT(char1. char2)is dragged from the Character Functions group in the Snippets window. Oracle and/or its affiliates. All rights reserved.

but does not exit. you can perform the following debugging tasks: • Find Execution Point goes to the next execution point. • Step Out leaves the current method and goes to the next statement. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. • Step Into goes to the first statement in the next method.• • • Use SQL Developer to debug PL/SQL functions and procedures. Use the Compile for Debug option to perform a PL/SQL compilation so that the procedure can be debugged. Debugging Procedures and Functions In SQL Developer. • Terminate halts and exits the execution. • Step Over bypasses the next method and goes to the next statement after the method. Copyright © 2010. thus allowing you to resume execution. Using the Debug menu options.25 Oracle University and TechnoLogica use only Debugging Procedures and Functions . • Resume continues execution. • Pause halts execution. instead. You cannot resume execution from this point. and to perform step into. Use the Debug menu options to set breakpoints. • Garbage Collection removes invalid objects from the cache in favor of more frequently accessed and more valid objects. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . click the Run or Debug icon on the Source tab toolbar. • Step to End of Method goes to the last statement of the current method. These options are also available as icons on the debugging toolbar. step over tasks. to start running or debugging from the beginning of the function or procedure. Oracle and/or its affiliates. you can debug PL/SQL procedures and functions. All rights reserved.

Database Reporting Copyright © 2010. and the rows are usually ordered by Owner. You can also create your own THESE user-defined eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . All rights reserved. click the Reports tab at the left of the window. the objects shown are only those visible to the database user associated with the selected database connection.26 Oracle University and TechnoLogica use only SQL Developer provides a number of predefined reports about the database and its objects. Individual reports are displayed in tabbed panes at the right of the window. COPYING eKIT MATERIALS FROM THIS reports. . These reports can be grouped into the following categories: • About Your Database reports • Database Administration reports • Table reports • PL/SQL reports • Security reports • XML reports • Jobs reports • Streams reports • All Objects reports • Data Dictionary reports • User-Defined reports To display reports. you can select (using a drop-down list) the database connection for which to display the report. and for each report. For reports about objects. Oracle and/or its affiliates. Database Reporting SQL Developer provides many reports about the database and its objects.

In the example in the slide. You can organize user-defined reports in folders. right-click the User Defined Reports node or any folder name under that node and select Add Folder.Creating a User-Defined Report Organize reports in folders. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. perform the following steps: 1. The complete SQL statement for retrieving the information to be displayed in the user-defined report is specified in the SQL box. specify the report name and the SQL query to retrieve information for the report. Then click Apply. All rights reserved. is stored in a file named UserReports. To create a folder for user-defined reports. An optional description is provided indicating that the report contains details of employees with salary >= 10000. Copyright © 2010. Right-click the User Defined Reports node under Reports. and you can create a hierarchy of folders and subfolders.xml under the directory for user-specific information. and select Add Report. In the Create Report dialog box. including any folders for these reports. You can also include an optional tool tip to be displayed when the cursor stays briefly over the report name in the Reports navigator display. 2. Oracle and/or its affiliates. Creating a User-Defined Report User-defined reports are reports created by SQL Developer users. Information about user-defined reports. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C .27 Oracle University and TechnoLogica use only Create and save user-defined reports for repeated use. To create a user-defined report. the report name is specified as emp_sal. .

28 Oracle University and TechnoLogica use only 1 . perform the following steps: 1.Search Engines and External Tools Shortcuts to frequently used tools 2 Links to popular search engines and discussion forums Copyright © 2010. From the Tools menu. 2. Oracle and/or its affiliates. and Dreamweaver. Microsoft Word. you have shortcut icons to some of the frequently used tools such as Notepad. SQL Developer has added quick links to popular search engines and discussion forums such as AskTom. To do so. select New to add new tools. All rights reserved. You can add external tools to the existing list or even delete shortcuts to tools that you do not use frequently. Google. available to you. In the External Tools dialog box. Search Engines and External Tools To enhance productivity of the SQL developers. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. and so on. select External Tools. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . Also. Select Delete to remove any tool from the list.

Setting Preferences Customize the SQL Developer interface and environment. The preferences are grouped into the following categories: • Environment • Accelerators (Keyboard shortcuts) • Code Editors • Database • Debugger • Documentation • Extensions • File Types • Migration • PL/SQL Compilers • PL/SQL Debugger THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. then Preferences. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . To modify SQL Developer preferences. select Tools. All rights reserved. In the Tools menu.29 Oracle University and TechnoLogica use only • • . Oracle and/or its affiliates. Setting Preferences You can customize many aspects of the SQL Developer interface and environment by modifying SQL Developer preferences according to your preferences and needs. Copyright © 2010. select Preferences.

3. 4. Open a terminal window and use the locate command to find the location of windowinglayout. perform the following steps to fix the problem: 1. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C . Exit from SQL Developer. Resetting the SQL Developer Layout While working with SQL Developer.30 Oracle University and TechnoLogica use only Resetting the SQL Developer Layout . All rights reserved. Go to the directory that has windowinglayout. Oracle and/or its affiliates.Copyright © 2010. 2. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.xml. if the Connections Navigator disappears or if you cannot dock the Log window in its original place.xml and delete it. Restart SQL Developer.

you should have learned how to use SQL Developer to do the following: • Browse. SQL Developer enables you to create and save your own special set of reports for repeated use. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I C .Summary Copyright © 2010. and edit database objects • Execute SQL statements and scripts in SQL Worksheet • Create and save custom reports . Using SQL Developer. Summary SQL Developer is a free graphical tool to simplify database development tasks. you can browse. and edit database objects. All rights reserved. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. create. Oracle and/or its affiliates.31 Oracle University and TechnoLogica use only In this appendix. You can use SQL Worksheet to run SQL statements and scripts. create.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Oracle University and TechnoLogica use only THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

Oracle and/or its affiliates. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Copyright © 2010. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Using SQL*Plus . All rights reserved.

edit SQL commands.After completing this appendix. Objectives You might want to create SELECT statements that can be used again and again. you should be able to do the following: • Log in to SQL*Plus • Edit SQL commands • Format the output using SQL*Plus commands • Interact with script files Copyright © 2010. You learn how to format output using SQL*Plus commands. Oracle and/or its affiliates.2 Oracle University and TechnoLogica use only Objectives . and save scripts in SQL*Plus. This appendix also covers the use of SQL*Plus commands to execute SQL statements. All rights reserved. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D .

When you enter a SQL statement. SQL*Plus is an Oracle tool that recognizes and submits SQL statements to the Oracle9i Server for execution. Features of SQL • Can be used by a range of users. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . Oracle SQL contains many extensions. SQL and SQL*Plus SQL is a command language used for communication with the Oracle server from any tool or application. it is stored in a part of memory called the SQL buffer and remains there until you enter a new SQL statement.SQL and SQL*Plus Interaction SQL statements Server Query results Buffer SQL scripts Copyright © 2010. including those with little or no programming experience • Is a nonprocedural language • Reduces the amount of time required for creating and maintaining systems • Is an English-like language Features of SQL*Plus • Accepts ad hoc entry of statements • Accepts SQL input from files • Provides a line editor for modifying SQL statements • Controls environmental settings • Formats query results into basic reports • Accesses local and remote databases THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.3 Oracle University and TechnoLogica use only SQL*Plus . It contains its own command language. All rights reserved. Oracle and/or its affiliates.

Oracle and/or its affiliates.SQL • A language • ANSI-standard • Keywords cannot be abbreviated. executes commands immediately Uses commands to format data THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. All rights reserved. SQL statements SQL buffer SQL*Plus • An environment • Oracle-proprietary • Keywords can be abbreviated. SQL and SQL*Plus (continued) The following table compares SQL and SQL*Plus: SQL Is a language for communicating with the Oracle server to access data Is based on American National Standards Institute (ANSI)–standard SQL Manipulates data and table definitions in the database Is entered into the SQL buffer on one or more lines Does not have a continuation character Cannot be abbreviated Uses a termination character to execute commands immediately Uses functions to perform some formatting SQL*Plus Recognizes SQL statements and sends them to the server Is the Oracle-proprietary interface for executing SQL statements Does not allow manipulation of values in the database Is entered one line at a time. not stored in the SQL buffer Uses a dash (–) as a continuation character if the command is longer than one line Can be abbreviated Does not require termination characters. SQL*Plus commands SQL*Plus buffer Copyright © 2010.4 Oracle University and TechnoLogica use only SQL Statements Versus SQL*Plus Commands . • Statements manipulate data and table definitions in the database. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . • Commands do not allow manipulation of values in the database.

Edit your SQL statement. SQL*Plus SQL*Plus is an environment in which you can: • Execute SQL statements to retrieve. print variable values.5 Oracle University and TechnoLogica use only Overview of SQL*Plus . add. load.• • • • • • • Log in to SQL*Plus. Execute saved files. store. and print messages to the screen Connect to the database. Load commands from the file to buffer to edit. and display column definitions THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Describe the table structure. modify. perform calculations on. Oracle and/or its affiliates. Execute SQL from SQL*Plus. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . All rights reserved. and run script files Send SQL statements from the SQL buffer to the Oracle server Modify SQL statements in the buffer Create and pass variables to SQL statements. manipulate the SQL*Plus environment. and print query results in the form of reports • Create script files to store SQL statements for repeated use in the future SQL*Plus commands can be divided into the following main categories: Category Environment Format File manipulation Execution Edit Interaction Miscellaneous Purpose Affect the general behavior of SQL statements for the session Format query results Save. and remove data from the database • Format. Save SQL statements to files and append SQL statements to files. Copyright © 2010.

Enter the sqlplus command shown in the slide. Instead. Enter the username. 3.) @database The database connect string Note: To ensure the integrity of your password. and database name. Logging In to SQL*Plus How you invoke SQL*Plus depends on which type of operating system you are running Oracle Database. password. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . Oracle and/or its affiliates. 2. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Enter your password at the password prompt. Right-click your Linux desktop and select terminal.6 Oracle University and TechnoLogica use only 1 . do not enter it at the operating system prompt. In the syntax: username Your database username password Your database password (Your password is visible if you enter it here. perform the following steps: 1. enter only your username. All rights reserved. To log in from a Linux environment.Logging In to SQL*Plus sqlplus [username[/password[@database]]] 2 Copyright © 2010.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D .Displaying the Table Structure Use the SQL*Plus DESCRIBE command to display the structure of a table: Copyright © 2010. All rights reserved. Oracle and/or its affiliates.--------------DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID NOT NULL NUMBER(4) NOT NULL VARCHAR2(30) NUMBER(6) NUMBER(4) THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. use this command: SQL> DESCRIBE DEPARTMENTS Name Null? Type ----------------------. In the syntax: tablename The name of any existing table. you can display the structure of a table using the DESCRIBE command.7 Oracle University and TechnoLogica use only DESC[RIBE] tablename . or synonym that is accessible to the user To describe the DEPARTMENTS table. Displaying the Table Structure In SQL*Plus.-------. view. The result of the command is a display of column names and data types as well as an indication if a column must contain data.

Displaying the Table Structure Name ----------------------DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID Null? Type -------.-----------NOT NULL NUMBER(4) NOT NULL VARCHAR2(30) NUMBER(6) NUMBER(4) Copyright © 2010. In the result: Null?: Specifies whether a column must contain data (NOT NULL indicates that a column must contain data. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . Oracle and/or its affiliates.8 Oracle University and TechnoLogica use only DESCRIBE departments . Displaying the Table Structure (continued) The example in the slide displays the information about the structure of the DEPARTMENTS table.) Type: Displays the data type for a column THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. All rights reserved.

SQL*Plus Editing Commands SQL*Plus commands are entered one line at a time and are not stored in the SQL buffer. SQL*Plus prompts you with a line number. The SQL prompt appears. Oracle and/or its affiliates. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. • You terminate the SQL buffer either by entering one of the terminator characters (semicolon or slash) or by pressing [Enter] twice. Command A[PPEND] text C[HANGE] / old / new Description Adds text to the end of the current line Changes old text to new in the current line C[HANGE] / text / CL[EAR] BUFF[ER] DEL DEL n DEL m n Deletes Deletes Deletes Deletes Deletes text from the current line all lines from the SQL buffer current line line n lines m to n inclusive Guidelines • If you press Enter before completing a command.• • • • • • • A[PPEND] text C[HANGE] / old / new C[HANGE] / text / CL[EAR] BUFF[ER] DEL DEL n DEL m n Copyright © 2010. All rights reserved.9 Oracle University and TechnoLogica use only SQL*Plus Editing Commands .

10 Oracle University and TechnoLogica use only SQL*Plus Editing Commands . Oracle and/or its affiliates. SQL*Plus commands are not stored in the buffer. end the first line with a hyphen (-).• • • • • • • • • I[NPUT] I[NPUT] text L[IST] L[IST] n L[IST] m n R[UN] n n text 0 text Copyright © 2010. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . SQL*Plus Editing Commands (continued) Command I[NPUT] I[NPUT] text L[IST] L[IST] n L[IST] m n R[UN] n n text 0 text Description Inserts an indefinite number of lines Inserts a line consisting of text Lists all lines in the SQL buffer Lists one line (specified by n) Lists a range of lines (m to n) inclusive Displays and runs the current SQL statement in the buffer Specifies the line to make the current line Replaces line n with text Inserts a line before line 1 Note: You can enter only one SQL*Plus command for each SQL prompt. All rights reserved. To continue a SQL*Plus command on the next line.

The new current line is displayed. can be abbreviated to just their first letter. • Use the A[PPEND] command to add text to the current line. and APPEND • Use the L[IST] command to display the contents of the SQL buffer. n. including LIST and APPEND. APPEND can be abbreviated to A. job_id 1* SELECT last_name. Note: Many SQL*Plus commands. The asterisk (*) beside line 2 in the buffer indicates that line 2 is the current line. • Change the number of the current line by entering the number (n) of the line that you want to edit.Using LIST. job_id 2* FROM employees Copyright © 2010. Any edits that you made apply to the current line. All rights reserved. The newly edited line is displayed. Verify the new contents of the buffer by using the LIST command. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . job_id LIST 1 SELECT last_name. LIST can be abbreviated to L. Oracle and/or its affiliates. and APPEND LIST 1 SELECT last_name 2* FROM employees 1* SELECT last_name A . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.11 Oracle University and TechnoLogica use only 1 . n. Using LIST.

In this case. Using the CHANGE Command • Use L[IST] to display the contents of the buffer. The new current line is displayed.12 Oracle University and TechnoLogica use only LIST 1* SELECT * from employees . replace the employees table with the departments table. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . • Use the C[HANGE] command to alter the contents of the current line in the SQL buffer. Oracle and/or its affiliates. • Use the L[IST] command to verify the new contents of the buffer. All rights reserved. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Using the CHANGE Command c/employees/departments 1* SELECT * from departments LIST 1* SELECT * from departments Copyright © 2010.

Runs a previously saved command file @ filename Runs a previously saved command file (same as START) ED[IT] Invokes the editor and saves the buffer contents to a file named afiedt.13 Oracle University and TechnoLogica use only SQL*Plus File Commands . SQL*Plus commands control the environment. Oracle and/or its affiliates. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D .sql. The default extension for the file name is . Use APPEND to add to an existing file.ext] STA[RT] filename [. format query results. The default extension is . OUT OFF|OUT] closes the spool file and sends the file results to the printer.ext]| Stores query results in a file. GET filename [. All rights reserved. You can use the commands described in the following table: Command Description SAV[E] filename [.ext] [REP[LACE]APP[END]] Saves current contents of SQL buffer to a file.sql. and manage files.ext]] Invokes the editor to edit the contents of a saved file SPO[OL] [filename[.ext] Writes the contents of a previously saved file to the SQL buffer. use REPLACE to overwrite an existing file.• • • • • • • SAVE filename GET filename START filename @ filename EDIT filename SPOOL filename EXIT Copyright © 2010. OFF closes the spool file. SQL*Plus File Commands SQL statements communicate with the Oracle server.buf ED[IT] [filename[. EXIT Quits SQL*Plus THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

use the symbol @ to run a script. Oracle and/or its affiliates. 107 rows selected. you can store frequently used scripts for use in the future. and EDIT Commands SAVE Use the SAVE command to store the current contents of the buffer in a file.14 Oracle University and TechnoLogica use only SAVE my_query Created file my_query . Using the SAVE.------------King 90 Kochhar 100 90 . START.. @my_query THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D .---------. All rights reserved.. department_id 2* FROM employees START my_query LAST_NAME MANAGER_ID DEPARTMENT_ID ------------------------. manager_id. In this way. Copyright © 2010. alternatively.Using the SAVE. START Use the START command to run a script in SQL*Plus. START Commands LIST 1 SELECT last_name. You can also.

Resources are not preallocated when SERVEROUTPUT is set. Oracle and/or its affiliates. n cannot be less than 2000 or greater than 1.000.000. For example. to read and display the data passed to DBMS_OUTPUT. The default size is now unlimited. • For additional information about SERVEROUTPUT. SQL*Plus does not display DBMS_OUTPUT data unless you first issue the SQL*Plus command SET SERVEROUTPUT ON as follows: SET SERVEROUTPUT ON Note • SIZE sets the number of bytes of the output that can be buffered within the Oracle Database server. use UNLIMITED unless you want to conserve physical memory. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. The default is UNLIMITED. to store data in database tables or query those tables. see Oracle Database PL/SQL User's Guide and Reference 11g. such as PUT_LINE. Because there is no performance penalty. All other PL/SQL input/output is done through APIs that interact with other programs. such as SQL*Plus. To see the result outside of PL/SQL requires another program. SET SERVEROUT[PUT] {ON | OFF} [SIZE {n | UNL[IMITED]}] [FOR[MAT] {WRA[PPED] | WOR[D_WRAPPED] | TRU[NCATED]}] Copyright © 2010. All rights reserved. SERVEROUTPUT Command Most of the PL/SQL programs perform input and output through SQL statements.15 Oracle University and TechnoLogica use only SERVEROUTPUT Command .• • • • • Use the SET SERVEROUT[PUT] command to control whether to display the output of stored procedures or PL/SQL blocks in SQL*Plus. the DBMS_OUTPUT package has procedures. The DBMS_OUTPUT line length limit is increased from 255 bytes to 32767 bytes. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D .

where previously you could only use SPOOL to create (and replace) a file.Using the SQL*Plus SPOOL Command Option Description file_name[. To spool output generated by commands in a script without displaying the output on the screen. use SET TERMOUT OFF. You must use quotes around file names containing white space. you must use PROMPT or a similar command to create the HTML page header and footer.2 or earlier to disable the CREATE.ext] [CRE[ATE] | REP[LACE] | APP[END]] | OFF | OUT] . All rights reserved.ext] Spools output to the specified file name CRE[ATE] Creates a new file with the name specified REP[LACE] Replaces the contents of an existing file. The SPOOL APPEND command does not parse HTML tags. To create a valid HTML file using SPOOL APPEND commands. SET TERMOUT OFF does not affect output from commands that run interactively.16 Oracle University and TechnoLogica use only SPO[OL] [file_name[. SET SQLPLUSCOMPAT[IBILITY] to 9. APP[END] Adds the contents of the buffer to the end of the file you specify OFF Stops spooling OUT Stops spooling and sends the file to your computer’s standard (default) printer Copyright © 2010. Using the SQL*Plus SPOOL Command The SPOOL command stores query results in a file or optionally sends the file to a printer. APPEND and SAVE parameters. The SPOOL command has been enhanced. REPLACE creates the file. REPLACE is the default. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D . If the file does not exist. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. or replace an existing file. You can now append to. Oracle and/or its affiliates.

STATISTICS displays SQL statement statistics. INSERT. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. The formatting of your AUTOTRACE report may vary depending on the version of the server to which you are connected and the configuration of the server. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D .The AUTOTRACE report includes both the optimizer -.execution path and the SQL statement execution -. refer to Oracle Database SQL Reference 11g. • For additional information about the EXPLAIN PLAN.17 Oracle University and TechnoLogica use only Using the AUTOTRACE Command . The DBMS_XPLAN package provides an easy way to display the output of the EXPLAIN PLAN command in several predefined formats. All rights reserved. refer to Oracle Database PL/SQL Packages and Types Reference 11g. or DELETE. UPDATE.statistics Copyright © 2010. Oracle and/or its affiliates. • For additional information about Execution Plans and the statistics. SET AUTOT[RACE] {ON | OFF | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] SET AUTOTRACE ON -. refer to Oracle Database Performance Tuning Guide 11g. Note • For additional information about the package and subprograms.• It displays a report after the successful execution of SQL DML statements such as SELECT. • The report can now include execution statistics and the query execution path. Using the AUTOTRACE Command EXPLAIN shows the query execution path by performing an EXPLAIN PLAN.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I D .18 Oracle University and TechnoLogica use only Summary . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. You can execute commands from the SQL prompt or from a script file.In this appendix. All rights reserved. Oracle and/or its affiliates. Summary SQL*Plus is an execution environment that you can use to send SQL commands to the database server and to edit and save SQL commands. you should have learned how to use SQL*Plus as an environment to do the following: • Execute SQL statements • Edit SQL statements • Format the output • Interact with script files Copyright © 2010.

Oracle and/or its affiliates. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Copyright © 2010. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Using JDeveloper . All rights reserved.

All rights reserved.After completing this appendix. You learn how to use JDeveloper for your database development tasks. you should be able to do the following: • List the key features of Oracle JDeveloper • Create a database connection in JDeveloper • Manage database objects in JDeveloper • Use JDeveloper to execute SQL Commands • Create and run PL/SQL Program Units Copyright © 2010. Oracle and/or its affiliates. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . you are introduced to JDeveloper.2 Oracle University and TechnoLogica use only Objectives . Objectives In this appendix. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

Oracle JDeveloper 11g initiates a new approach to J2EE development with features that enable visual and declarative development. It has the features to use the latest industry standards for Java. It supports every stage of the software development life cycle (SDLC) from modeling to deploying. This innovative approach makes J2EE development simple and efficient. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Oracle JDeveloper Oracle JDeveloper is an integrated development environment (IDE) for developing and deploying Java applications and Web services. All rights reserved. XML. and SQL while developing an application. Oracle and/or its affiliates.Copyright © 2010.3 Oracle University and TechnoLogica use only Oracle JDeveloper . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E .

A connection serves several purposes from browsing the database and building applications.4 Oracle University and TechnoLogica use only Database Navigator .Copyright © 2010. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Database Navigator Using Oracle JDeveloper. All rights reserved. you can store the information necessary to connect to a database in an object called “connection.” A connection is stored as part of the IDE settings. Oracle and/or its affiliates. and can be exported and imported for easy sharing among groups of users. all the way through to deployment.

5 Oracle University and TechnoLogica use only 1 Click the New Connection icon in the Database Navigator. and the SID. You can create and test connections for multiple databases and for multiple schemas. Creating Connection A connection is an object that specifies the necessary information for connecting to a specific database as a specific user of that database. Click Test Connection. . Click Test to ensure that the connection has been set correctly. Click OK. To create a database connection. All rights reserved. 3. Enter the username and password of the schema that you want to connect to. 4 Click OK Copyright © 2010. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Enter the SID of the Database you want to connect. Oracle and/or its affiliates. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. perform the following steps: 1. Click the New Connection icon in the Database Navigator. enter the Username. enter the connection name. 4.Creating Connection 2 3 In the Create Database Connection window. In the Create Database Connection window. Password. 2.

grants. constraints. You can see the definition of the objects broken into tabs of information that is pulled out of the data dictionary. the details about columns. you can use the Database Navigator to browse through many objects in a database schema including Tables. Procedures. Views. Oracle and/or its affiliates. Indexes. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Triggers. For example. statistics. and Types. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Browsing Database Objects After you create a database connection. if you select a table in the Navigator. Packages. All rights reserved.6 Oracle University and TechnoLogica use only Use the Database Navigator to: • Browse through many objects in a database schema • Review the definitions of objects at a glance . triggers.Browsing Database Objects Copyright © 2010. and so on are displayed on an easy-to-read Database Navigator.

Executing SQL Statements 1 3 Copyright © 2010. Select the connection. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Executing SQL Statements To execute a SQL statement. Execute the SQL command by clicking: 1. Click the Open SQL Worksheet icon. All rights reserved.7 Oracle University and TechnoLogica use only 2 . The output is as follows: THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 2. perform the following steps: 1. The output is as follows: 2. The Run Script button or by pressing F5. 3. Oracle and/or its affiliates. The Execute statement button or by pressing F9.

All rights reserved. You can then edit the subprogram to suit your need. Oracle and/or its affiliates. Enter a valid name for the function. Right-click a folder corresponding to the object type (Procedures. perform the following steps: 1.2 1 3 Skeleton of the function Copyright © 2010. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. A skeleton definition is created and opened in the Code Editor. Select and expand a database connection.8 Oracle University and TechnoLogica use only Creating Program Units . Select View > Database Navigator. 3. or procedure and click OK. Packages. Functions). Creating Program Units To create a PL/SQL program unit.” 2. Choose “New [Procedures|Packages|Functions]. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . package.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Oracle and/or its affiliates. All rights reserved. Compiling After editing the skeleton definition. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you can also press [Ctrl] + [Shift] + [F9] to compile. you need to compile the program unit. Alternatively.Compilation with errors Compilation without errors Copyright © 2010. Right-click the PL/SQL object that you need to compile in the Connection Navigator.9 Oracle University and TechnoLogica use only Compiling . and then select Compile.

right-click the object and click Run.10 Oracle University and TechnoLogica use only Running a Program Unit . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Oracle and/or its affiliates.Copyright © 2010. After you change the values. Running a Program Unit To execute the program unit. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. The output is displayed in the Message-Log window. click OK. You may need to change the NULL values with reasonable values that are passed into the program unit. All rights reserved. The Run PL/SQL dialog box appears.

Oracle and/or its affiliates. All rights reserved.11 Oracle University and TechnoLogica use only Dropping a Program Unit . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Dropping a Program Unit To drop a program unit. The object is dropped from the database. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . click Apply. The Drop Confirmation dialog box appears.1 2 Copyright © 2010. right-click the object and select Drop.

or UI model data. UI structure. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Structure Window The Structure window offers a structural view of the data in the document currently selected in the active window of those windows that participate in providing structure: the navigators. For a Java file. For an XML file. the default editor is assumed. Oracle and/or its affiliates. To change the view on the structure for the current selection. The Structure window is dynamic. you can view the document data in a variety of ways. In the Structure window. the editors and viewers. and the Property Inspector. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you can view code structure. The structures available for display are based upon document type. design structure.12 Oracle University and TechnoLogica use only Structure Window . All rights reserved. When the current selection is a node in the navigator. you can view XML structure. as is pertinent to the currently active editor.Copyright © 2010. tracking always the current selection of the active window (unless you freeze the window’s contents on a particular view). click a different structure tab. Click View > Structure window to view the Structure window. or UI model data.

or you can open multiple views of different files. Selecting an editor tab opens the file in that editor. Clicking a document tab gives that file focus. bringing it to the foreground of the window in the current editor. You can view your project files all in one single editor window. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. you can open multiple views of the same file. All rights reserved. Oracle and/or its affiliates.13 Oracle University and TechnoLogica use only Editor Window . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Editor Window Double-clicking the name of a program unit opens it in the Editor window. The tabs at the top of the editor window are the document tabs.Copyright © 2010. The tabs at the bottom of the editor window for a given file are the editor tabs.

Complex data types such as entity objects.Navigator can contain individual files (such as Java source files). THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.14 Oracle University and TechnoLogica use only Application Navigator . All rights reserved. UML diagrams. Oracle and/or its affiliates. abstract manner. While the Applications . The raw files that make up these abstract nodes appear in the Structure window. EJB. or Web services appear in this navigator as single nodes.Navigator provides an infrastructure that the different extensions can plug in to and use to organize their data and menus in a consistent.Copyright © 2010. The Applications .Navigator gives you a logical view of your application and the data it contains. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E . Application Navigator The Applications . it is designed to consolidate complex data.

any public static methods in JDeveloper using the settings in the profile. Create a deployment profile. Deploying Java Stored Procedures Create a deployment profile for Java stored procedures. optionally. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. All rights reserved. 2. perform the following steps: 1. 3.15 Oracle University and TechnoLogica use only Before deploying Java stored procedures. Deploying to the database uses the information provided in the Deployment Profile Wizard and two Oracle Database utilities: • loadjava loads the Java class containing the stored procedures to an Oracle database. Publishing enables the Java methods to be called as PL/SQL functions or procedures. Oracle and/or its affiliates.Deploying Java Stored Procedures 1 2 3 Copyright © 2010. Deploy the objects. Create a database connection. • publish generates the PL/SQL call–specific wrappers for the loaded public static methods. . and then deploy the classes and. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E .

Publishing Java to PL/SQL The slide shows the Java code and illustrates how to publish the Java code in a PL/SQL procedure. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E .Publishing Java to PL/SQL 2 Copyright © 2010. Oracle and/or its affiliates. All rights reserved. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.16 Oracle University and TechnoLogica use only 1 .

html Oracle JDeveloper 11g Product Documentation http://www. html Oracle JDeveloper 11g Discussion Forum http://forums.oracle.jspa?forumID=8 3 Copyright © 2010. All rights reserved.oracle. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.oracle.17 Oracle University and TechnoLogica use only How Can I Learn More About JDeveloper 11g? . Oracle and/or its affiliates.com/forums/forum. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E .Topic Website Oracle JDeveloper Product Page http://www.com/technology/products/jdev/index. html Oracle JDeveloper 11g Tutorials http://www.com/technology/obe/obe11jdev/11/in dex.oracle.com/technology/documentation/jdev.

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Oracle and/or its affiliates. All rights reserved. you should have learned to do the following: • List the key features of Oracle JDeveloper • Create a database connection in JDeveloper • Manage database objects in JDeveloper • Use JDeveloper to execute SQL Commands • Create and run PL/SQL Program Units Copyright © 2010.18 Oracle University and TechnoLogica use only Summary . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I E .In this appendix.

Oracle and/or its affiliates. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle University and TechnoLogica use only Oracle Join Syntax .Copyright © 2010. All rights reserved. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

2 Oracle University and TechnoLogica use only Objectives . Objectives This lesson explains how to obtain data from more than one table. Note: Information about joins is found in the section on “SQL Queries and Subqueries: Joins” in Oracle Database SQL Language Reference 11g. Oracle and/or its affiliates. Release 1 (11.After completing this appendix. Therefore. A join is used to view information from multiple tables. you should be able to do the following: • Write SELECT statements to access data from more than one table using equijoins and nonequijoins • Join a table to itself by using a self-join • View data that generally does not meet a join condition by using outer joins • Generate a Cartesian product of all rows from two or more tables Copyright © 2010. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. All rights reserved.1). COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . you can join tables together to view information from more than one table.

and access data from both of them. • Department IDs exist in both the EMPLOYEES and DEPARTMENTS tables. In the example in the slide. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … Copyright © 2010. the report displays data from two separate tables: • Employee IDs exist in the EMPLOYEES table.3 Oracle University and TechnoLogica use only … . Obtaining Data from Multiple Tables Sometimes you need to use data from more than one table. • Department names exist in the DEPARTMENTS table. you need to link the EMPLOYEES and DEPARTMENTS tables. All rights reserved. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . To produce the report. Oracle and/or its affiliates.

in which all combinations of rows are displayed. In other words. All rights reserved. Copyright © 2010.Cartesian Products • A Cartesian product is formed when: • To avoid a Cartesian product. However. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Therefore. A Cartesian product tends to generate a large number of rows and the result is rarely useful. Oracle and/or its affiliates. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . the result is a Cartesian product. always include a valid join condition in a WHERE clause. you should always include a valid join condition unless you have a specific need to combine all rows from all tables. Cartesian Products When a join condition is invalid or omitted completely. Cartesian products are useful for some tests when you need to generate a large number of rows to simulate a reasonable amount of data. all rows in the first table are joined to all rows in the second table.4 Oracle University and TechnoLogica use only – A join condition is omitted – A join condition is invalid – All rows in the first table are joined to all rows in the second table .

5 Oracle University and TechnoLogica use only … . departments. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . department_name dept_name FROM employees. Oracle and/or its affiliates. all rows (20 rows) from the EMPLOYEES table are joined with all rows (8 rows) in the DEPARTMENTS table. SELECT last_name. All rights reserved. Because no join condition has been specified. thereby generating 160 rows in the output. The example in the slide displays the last name of the employee and the department name from the EMPLOYEES and DEPARTMENTS tables.Generating a Cartesian Product EMPLOYEES (20 rows) DEPARTMENTS (8 rows) Cartesian product: 20 x 8 = 160 rows … … Copyright © 2010. … THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. respectively. Generating a Cartesian Product A Cartesian product is generated when a join condition is omitted.

Oracle and/or its affiliates. the join syntax was proprietary. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . Oracle does not have an equivalent syntax to support the FULL OUTER JOIN of the SQL:1999– compliant join syntax. All rights reserved. you can use Oracle’s join syntax. Note: Before the Oracle9i release.6 Oracle University and TechnoLogica use only • • • • . THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Types of Joins To join tables. The SQL:1999–compliant join syntax does not offer any performance benefits over the Oracle-proprietary join syntax.Types of Oracle-Proprietary Joins Equijoin Nonequijoin Outer join Self-join Copyright © 2010.

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. All rights reserved.column. For example. a join condition is used.column2 Guidelines • When writing a SELECT statement that joins tables. write a simple join condition in the WHERE clause. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . Rows in one table can be joined to rows in another table according to common values that exist in the corresponding columns (that is. table2.column1 = Is the condition that joins (or relates) the tables together table2.column2. In the syntax: table1. • To join n tables together.Joining Tables Using Oracle Syntax Use a join to query data from more than one table: table1.column Denotes the table and column from which data is retrieved table1. Copyright © 2010. precede the column name with the table name for clarity and to enhance database access. you need a minimum of n-1 join conditions. table2 table1. To display data from two or more related tables. to join four tables. usually primary and foreign key columns). • Prefix the column name with the table name when the same column name appears in more than one table. Oracle and/or its affiliates. Joining Tables Using Oracle Syntax When data from more than one table in the database is required. • If the same column name appears in more than one table.column table1. This rule may not apply if your table has a concatenated primary key. • Write the join condition in the WHERE clause.column1 = table2. the column name must be prefixed with the table name. in which case more than one column is required to uniquely identify each row.7 Oracle University and TechnoLogica use only SELECT FROM WHERE . a minimum of three joins is required.

using a table prefix improves performance. All rights reserved. instead of full table name prefixes. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . Just as a column alias gives a column another name. particularly if table names are lengthy.8 Oracle University and TechnoLogica use only • . Copyright © 2010. Qualifying Ambiguous Column Names When joining two or more tables.Qualifying Ambiguous Column Names • • • Use table prefixes to qualify column names that are in multiple tables. but shorter aliases are better than longer ones. – Keeps SQL code smaller. Use table prefixes to improve performance. Therefore. • If a table alias is used for a particular table name in the FROM clause. Without the table prefixes. that table alias must be substituted for the table name throughout the SELECT statement. uses less memory • Use column aliases to distinguish columns that have identical names. you need to qualify the names of the columns with the table name to avoid ambiguity. but reside in different tables. followed by a space and then the table alias. The table name is specified in full. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Table aliases give a table a shorter name. Use table aliases. the EMPLOYEES table can be given an alias of e. If there are no common column names between the two tables. Qualifying column names with table names can be very time consuming. Table aliases help to keep SQL code smaller. a table alias gives a table another name. and the DEPARTMENTS table an alias of d. Oracle and/or its affiliates. • A table alias is valid only for the current SELECT statement. the DEPARTMENT_ID column in the SELECT list could be from either the DEPARTMENTS table or the EMPLOYEES table. you can use table aliases. thereby using less memory. because you tell the Oracle server exactly where to find the columns. • Table aliases should be meaningful. it is necessary to add the table prefix to execute your query. For example. instead of table names. However. Guidelines • Table aliases can be up to 30 characters in length. Therefore. there is no need to qualify the columns.

Equijoins DEPARTMENTS … Primary key Foreign key Copyright © 2010. The relationship between the EMPLOYEES and DEPARTMENTS tables is an equijoin. you compare the value in the DEPARTMENT_ID column in the EMPLOYEES table with the DEPARTMENT_ID values in the DEPARTMENTS table. values in the DEPARTMENT_ID column in both tables must be equal. Often. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . All rights reserved. Equijoins To determine an employee’s department name. Oracle and/or its affiliates. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. that is. Note: Equijoins are also called simple joins or inner joins.9 Oracle University and TechnoLogica use only EMPLOYEES . this type of join involves primary and foreign key complements.

department name. Other columns that are not present in both the tables need not be qualified by a table alias.department_id. e.location_id FROM employees e. Note: When you use the Execute Statement icon to run the query. Oracle and/or its affiliates. employee number. .last_name.DEPARTMENTS table • The WHERE clause specifies how the tables are to be joined: e.department_id. it must be prefixed with the table alias to avoid ambiguity. All rights reserved. which are columns in the EMPLOYEES table .department_id Because the DEPARTMENT_ID column is common to both tables.EMPLOYEES table .employee_id. departments d WHERE e. e.Employee last name.department_id. and department number. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . Retrieving Records with Equijoins In the example in the slide: • The SELECT clause specifies the column names to retrieve: .department_id = d. which are columns in the DEPARTMENTS table • The FROM clause specifies the two tables that the database must access: . d.Retrieving Records with Equijoins … Copyright © 2010. but it is recommended for better performance. and location ID.Department number.10 Oracle University and TechnoLogica use only SELECT e.department_id = d. d. SQL Developer suffixes a “_1” to differentiate between the two DEPARTMENT_IDs.

d.location_id.department_id. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F .location_id = l. the LOCATIONS table is joined to the DEPARTMENTS table by the LOCATION_ID column.Retrieving Records with Equijoins: Example Copyright © 2010. which is the only column of the same name in both the tables. locations l WHERE d.department_name. Oracle and/or its affiliates. d.11 Oracle University and TechnoLogica use only SELECT d.location_id. All rights reserved. .city FROM departments d. Table aliases are used to qualify the columns and avoid ambiguity. Retrieving Records with Equijoins: Example In the example in the slide. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. l.

locations l WHERE d.department_id = d. you need an additional condition in the WHERE clause. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.location_id = l. 50). e.location_id AND d. departments d WHERE e. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F .department_name.department_name FROM employees e. SELECT e.city FROM departments d. Oracle and/or its affiliates. you may have criteria for your WHERE clause to restrict the rows under consideration for one or more tables in the join.12 Oracle University and TechnoLogica use only SELECT d. d. The example in the slide limits the rows of output to those with a department ID equal to 20 or 50: For example.department_id IN (20. All rights reserved. l.department_id.department_id AND last_name = 'Matos'.last_name. d. Additional Search Conditions Using the AND Operator In addition to the join. to display employee Matos’ department number and department name.department_id.Additional Search Conditions Using the AND Operator Copyright © 2010. .

location_id = l.last_name.city employees e. DEPARTMENTS. For example. the department name. All rights reserved. and LOCATIONS tables.13 Oracle University and TechnoLogica use only EMPLOYEES . For example. Joining More than Two Tables Sometimes you may need to join more than two tables. … THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. to join three tables.department_name.department_id = d. Oracle and/or its affiliates. departments d. d.Joining More than Two Tables DEPARTMENTS LOCATIONS … To join n tables together. locations l e. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . you need a minimum of n–1 join conditions. you have to join the EMPLOYEES. Copyright © 2010.department_id d. l. to display the last name.location_id. a minimum of two joins is required. SELECT FROM WHERE AND e. and the city for each employee.

The relationship is obtained using an operator other than the equality operator (=). Nonequijoins A nonequijoin is a join condition containing something other than an equality operator. each employee can be graded based on the salary. Oracle and/or its affiliates. Therefore. The relationship between the EMPLOYEES table and the JOB_GRADES table is an example of a nonequijoin. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. The SALARY column in the EMPLOYEES table ranges between the values in the LOWEST_SAL and HIGHEST_SAL columns of the JOB_GRADES table. All rights reserved.14 Oracle University and TechnoLogica use only EMPLOYEES . the GRADE_LEVEL column can be used to assign grades to each employee. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . Copyright © 2010. Therefore.Nonequijoins … JOB_GRADES JOB_GRADES table defines LOWEST_SAL and HIGHEST_SAL range of values for each GRADE_LEVEL.

Table aliases have been specified in the example in the slide for performance reasons. job_grades j WHERE e.grade_level FROM employees e.salary. Note: Other conditions (such as <= and >=) can be used. The salary must be between any pair of the low and high salary ranges.lowest_sal AND j. • All of the employees’ salaries lie within the limits that are provided by the job grade table. e. but should be used only for logical simplicity. . the salary value for an employee can lie only between the low salary and high salary values of one of the rows in the salary grade table. No employee is repeated in the list. not because of possible ambiguity. Retrieving Records with Nonequijoins The example in the slide creates a nonequijoin to evaluate an employee’s salary grade.last_name.salary BETWEEN j. That is. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . Oracle and/or its affiliates. using BETWEEN has no performance benefits.15 Oracle University and TechnoLogica use only SELECT e. It is important to note that all employees appear exactly once when this query is executed. j. Remember to specify the low value first and the high value last when using the BETWEEN condition. That is. The Oracle server translates the BETWEEN condition to a pair of AND conditions.highest_sal. no employee earns less than the lowest value contained in the LOWEST_SAL column or more than the highest value contained in the HIGHEST_SAL column.Retrieving Records with Nonequijoins … Copyright © 2010. There are two reasons for this: • None of the rows in the job grade table contain grades that overlap. All rights reserved. but BETWEEN is the simplest. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Therefore.

there is an employee whose DEPARTMENT_ID is set to NULL. or to return the employee record that does not belong to any department. For example.Returning Records with No Direct Match with Outer Joins EMPLOYEES … There are no employees in department 190. in the equijoin condition of the EMPLOYEES and DEPARTMENTS tables. so this row will also not appear in the query result of an equijoin. department ID 190 does not appear because there are no employees with that department ID recorded in the EMPLOYEES table. the row does not appear in the query result. Returning Records with No Direct Match with Outer Joins If a row does not satisfy a join condition. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F .16 Oracle University and TechnoLogica use only DEPARTMENTS . Copyright © 2010. Similarly. Oracle and/or its affiliates. All rights reserved. you can use the outer join. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. To return the department record that does not have any employees.

column FROM table1.column = Is the condition that joins (or relates) the tables together table2. The outer join operator is the plus sign (+).column. Oracle and/or its affiliates. In the syntax: table1.column(+) = table2. table2.column.17 Oracle University and TechnoLogica use only • .column (+) Is the outer join symbol. but not on both sides (Place the outer join symbol following the name of the column in the table without the matching rows.column FROM table1.Outer Joins: Syntax • You use an outer join to see rows that do not meet the join condition. table2. All rights reserved.column(+). COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . Outer Joins: Syntax Missing rows can be returned if an outer join operator is used in the join condition. Copyright © 2010. which can be placed on either side of the WHERE clause condition.) THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. SELECT table1. and is placed on the “side” of the join that is deficient in the information. The operator is a plus sign enclosed with parentheses (+). This operator has the effect of creating one or more null rows. to which one or more rows from the nondeficient table can be joined.column = table2. table2 WHERE table1. table2 WHERE table1.column. SELECT table1.

e. and department names. Using Outer Joins The example in the slide displays employee last names. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. It returns those rows. Outer Join Restrictions • The outer join operator can appear only on one side of the expression—the side in which the information is missing. The Contracting department does not have any employees. d. All rights reserved.department_id.department_id . • A condition involving an outer join cannot use the IN operator or be linked to another condition by the OR operator. department IDs. Oracle and/or its affiliates.department_id(+) = d.last_name. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . departments d WHERE e.department_name FROM employees e. from one table.Using Outer Joins … Copyright © 2010. . that have no direct match in the other table. Note: Oracle’s join syntax does not have an equivalent for the FULL OUTER JOIN of the SQL:1999– compliant join syntax. The empty value is shown in the output.18 Oracle University and TechnoLogica use only SELECT e.

departments d WHERE e. All rights reserved. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F .19 Oracle University and TechnoLogica use only SELECT e. e. Outer Join: Another Example The query in the example in the slide retrieves all rows in the EMPLOYEES table.department_id = d.department_name FROM employees e. Oracle and/or its affiliates.last_name.department_id(+) . even if there is no match in the DEPARTMENTS table. d.Outer Join: Another Example … Copyright © 2010.department_id. .

you look in the table twice.20 Oracle University and TechnoLogica use only EMPLOYEES (WORKER) . Lorentz’s manager number is 103. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. The second time you look in the EMPLOYEE_ID column to find 103 and the LAST_NAME column to find Hunold. you need to: • Find Lorentz in the EMPLOYEES table by looking at the LAST_NAME column • Find the manager number for Lorentz by looking at the MANAGER_ID column. Hunold’s employee number is 103. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . you need to join the EMPLOYEES table to itself.Joining a Table to Itself … EMPLOYEES (MANAGER) … MANAGER_ID in the WORKER table is equal to EMPLOYEE_ID in the MANAGER table. For example. The first time you look in the table to find Lorentz in the LAST_NAME column and the MANAGER_ID value of 103. or perform a self-join. Oracle and/or its affiliates. Joining a Table to Itself Sometimes you need to join a table to itself. • Find the name of the manager with EMPLOYEE_ID 103 by looking at the LAST_NAME column. so Hunold is Lorentz’s manager. To find the name of each employee’s manager. to find the name of Lorentz’s manager. All rights reserved. In this process. Copyright © 2010.

All rights reserved. In this example. Oracle and/or its affiliates. for the same table. there are two aliases.employee_id . Self-Join: Example The example in the slide joins the EMPLOYEES table to itself. . the WHERE clause contains the join that means “where a worker’s manager number matches the employee number for the manager.21 Oracle University and TechnoLogica use only SELECT worker.manager_id = manager. To simulate two tables in the FROM clause. employees manager WHERE worker.last_name FROM employees worker.Self-Join: Example … Copyright © 2010. EMPLOYEES.” THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. namely worker and manager. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F .last_name || ' works for ' || manager.

22 Oracle University and TechnoLogica use only In this appendix. Summary There are multiple ways to join tables. Oracle and/or its affiliates. you should have learned how to use joins to display data from multiple tables by using Oracle-proprietary syntax. Types of Joins • Equijoins • Nonequijoins • Outer joins • Self-joins Cartesian Products A Cartesian product results in a display of all combinations of rows. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. Table aliases can help to keep SQL code smaller by conserving memory. All rights reserved. Table Aliases • • Table aliases speed up database access. . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F .Summary Copyright © 2010. This is done by omitting the WHERE clause.

Practice F: Overview This practice is intended to give you practical experience in extracting data from more than one table using the Oracle join syntax. THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.23 Oracle University and TechnoLogica use only This practice covers the following topics: • Joining tables by using an equijoin • Performing outer and self-joins • Adding conditions . COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED Oracle Database: SQL Fundamentals I F . All rights reserved. Oracle and/or its affiliates.Practice F: Overview Copyright © 2010.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Oracle University and TechnoLogica use only THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Oracle University and TechnoLogica use only Index THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

1-11. 2-6. 4-38. 7-10. 1-18. 6-14. 8-6.Alias 1-3. 2-23. 1-20. 2-30. 4-39. 2-16. 2-8. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . 6-36. 8-28. 3-13 AND Operator 2-16. 8-24. 1-10. F-10. 1-19. 8-17. 8-30 ALTER TABLE Statement 10-35. 2-38. 6-35. 4-44 Character strings 1-3. 10-34. 1-10. 1-29. 5-14. 10-27. 1-19. 4-40. 3-11. 5-15. F-11. 1-19. F-15.2 Oracle University and TechnoLogica use only A . 6-32. 4-14. 10-33. 8-12. 4-43 CHECK Constraint 9-8. 1-10. 1-19. 5-27. 1-16. 1-21. 5-8. 8-27. F-22 CASE Expression 4-32. 7-21 Arithmetic Expressions 1-3. F-5. 8-16. 1-18. 6-22. 2-20. 1-25. 2-5 Arithmetic Operators 1-11. 6-8. 10-6. 1-21. 5-5. 3-25. 4-37. 6-36. 9-15. 1-16. I-24 AVG 5-3. 8-3. 5-11. 5-26. 5-7. 7-17. 6-7. 8-21. F-8. 5-27. 1-5. 6-7. 8-18. C-8. 1-20. 4-35 Column Alias 1-3. 3-13. 2-24. 8-29. 2-33. 7-13 B BETWEEN Operator 2-10 BI Publisher I-14 C Cartesian Product 6-2. 2-9. 4-25. 10-3. 7-18. 1-25. F-12 ANY Operator 7-3. 2-20 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 7-9. 1-20. 5-28. 6-31. 8-7. 10-15. 1-25. 6-6. F-8 Comparison Operators 2-8. 1-22. I-30 Ampersand Substitution 2-2. 3-32 Attributes I-22. 10-33. 1-21. 2-21. 10-11. 6-33. 2-5. 5-25. 1-15. 10-36 Alternative Quote (q) Operator 1-23 American National Standards Institute 4-4. 6-19. 2-38. 6-16. 9-21 Concatenation Operator 1-3. 2-6. 4-34. 5-23. 5-12. 1-16. 4-25. F-21. 1-20. 1-9. 1-25. 3-26. 4-17. 6-34. 6-24. 10-37 COALESCE Function 4-33. 5-14. 10-31. 1-19. 1-29. 2-39. 1-25. 1-17. F-2. 1-10. 5-16. 5-20. F-4. 2-24. 1-10. 1-17. 2-7. 6-25. 6-5. F-22 ALL Operator 7-19. 2-29. 1-9. 1-16. 1-12. I-23. 6-3. 1-16.

10-7. C-3. 10-14. 3-4. C-16. 10-37. I-5 COUNT Function 5-9 CREATE TABLE Statement 9-12. 9-42. F-2. 6-11. 10-12. 4-1. 9-25. 10-40. C-8. 10-34. 10-3. C-4. D-5. 4-4. C-9. 5-15. 9-9 CURRVAL 10-9. D-6. 10-40. 9-26. 7-8. 10-15. 9-47. 10-6. 10-6. E-6. 1-15. 10-31. 4-29. E-11. I-15. 10-4. 4-9. E-14. I-28. I-13. 9-12. 9-26. D-15. 2-2. 10-29. 10-31. E-4. 9-25. 9-42 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 4-44. 4-28. I-36. 9-9. I-38. 8-13. 9-43. 8-19. 6-36 CURRENT_DATE 3-24. I-9. I-14. 3-5. 10-37. 9-19. C-31. 9-21. 9-19. 10-20. C-29. I-30. I-16 Database 1-2. 10-34. 10-40. 9-40. 5-18. E-15. C-15. 4-44. 5-6. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . C-11. 10-11. I-12. 10-40. C-10. 10-38. I-19. I-27. 10-13. 6-36. 10-16. I-17. I-33. 10-7. I-22. I-2. 10-2. 9-3. 10-5. C-17. 9-34. 10-32. 3-21. 10-33. 1-14. 10-41 Creating a Database Connection C-7. 10-11. I-34. 6-6. 9-33. C-12. 3-28. 3-25. C-19. I-4. 10-6. 3-12. 10-11. 10-15. 10-15. 9-39. 10-2. E-6. 3-4. F-22. 9-15. 10-11. C-26. 3-24. 10-34. 10-6. D-7. 5-28. C-10. 10-34. 6-2. 9-13. I-3. 10-37. 10-27 D Data Types 1-11. 10-14. B-2. 8-25. 9-24. 10-10. C-6. D-17. 9-8. 9-8. 8-22. 10-31. 3-12. 1-26. I-10. D-3. E-18. 10-32. I-29. 4-2. I-16. C-9 Cross Joins 6-5. 10-31. 10-3. I-39 Conversion Functions 3-7. 10-22. 3-16. 3-26. 3-33. I-16. 4-4. 10-15. I-20. 9-20. C-2. 10-19. 10-30. 3-9. I-31. D-4. 4-4. C-8. 10-41. F-10. 10-3. 10-37. 9-44. 5-8.3 Oracle University and TechnoLogica use only C . 9-31. 2-7. 9-27. 9-13. I-18. 3-10. I-32. C-5. 10-8. 9-4. E-5. 1-27. C-7. 10-17.Constraints 1-14. 9-4. 1-4. 1-29. 9-27. 4-9. E-2. 10-25. 10-27. 4-31. I-9. 10-3. 6-9. 6-34. D-18. 10-13. 9-41. 10-36. 9-39. I-37. 3-11. I-8. E-8. 9-45. 10-21. F-7. I-11. 10-39. 10-17. I-40 Database Transactions 9-3. 10-2. C-13. 10-18. I-39.

4-9. 5-9. 10-15. D-15. 8-30. 1-19. 2-23. 4-42. 10-33. 3-3. 9-45. 3-29. 5-8. I-34 Datetime Data Types 10-14 DBMS 9-43. 10-27. 10-6. 5-28. 9-9. 10-14. 3-32. 9-2. 10-16. 3-4. I-23 Equijoins 6-2. 9-42 DESCRIBE Command 1-3. 3-23. I-16. 2-8. C-31. 9-19. 6-23. 10-38. 9-43. D-5. 4-7. 2-25. 3-30. I-2. 10-22. 9-18. 4-36. 3-15. 9-44. D-18. 1-16. I-4. 4-6. 9-23. 9-35. I-25. I-17. 10-25. 4-2. 9-47. 9-3. 9-25. 9-15.Date 1-9. 6-24. 3-24. E-2. F-11. 4-8. 3-5. 2-28. 5-25 DUAL Table 3-17 Duplicate Rows 1-24. 3-27. 10-10. 10-41. I-27 E Entity Relationship B-3. 4-12. 9-4. 4-23. 9-17. 5-10. 9-47 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 5-12. 9-40. 1-21. D-7 DISTINCT Keyword 1-3. I-31. 10-29. 4-29. 8-6. 4-16. 5-6. 3-20. 3-2. 8-10. 10-10. F-9. 1-27. 1-24. 4-40. 9-42. 8-16. 9-10. 10-37 DELETE Statement 9-3. 9-42. 2-12. 4-36 F FOR UPDATE clause 9-3. F-2. 4-39. 9-21. 4-23. I-39 DECODE Function 4-37. C-17. 2-24. 4-7. D-2. 4-3. 10-39. 5-3. 2-7. I-18. 10-31. 9-24. 4-5. 9-39. 4-20. 1-25. 9-13. 3-33. 4-4. 9-39. 6-36. E-18 Execute Statement icon 1-8. 4-15. 1-16. I-22. 10-9. 4-21. 10-26. 4-10. 10-28. 10-20. 9-7. 4-45. 3-26. 9-25. 4-27. 4-44. 3-17. 1-10. 6-22.4 Oracle University and TechnoLogica use only D . D-17. 3-25. I-22. 6-25. 9-14. I-18. 4-13. 3-8. 6-3. 10-12. C-15. 6-8. 8-8. 4-43. 9-41. 2-31. C-10. 6-35. 5-6 DEFAULT Option 10-3. C-11. 4-8. 9-30. 9-22. 4-41. 6-12. 1-19. 9-40. 9-44. 8-13. 3-28. 3-18. F-22 Execute SQL C-2. F-10. I-9. 1-10. 1-26. I-17. 9-19. 2-11. I-27. B-3. 1-25. 8-17. 9-13. 9-25. 1-11. 10-33. I-21. 9-45. E-14. 1-20. D-17. 6-19. 9-48. 10-36. 4-11. F-14. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . 3-7. 10-11. 9-39. 4-9. 4-22. F-10 Explicit Data Type Conversion 4-3. 9-16. 9-29. 9-19. 9-43. 4-25. 3-21. 4-14. 10-9. 9-13. F-15. 4-44. 4-10. 10-34. 3-22. 4-27. 6-16. 9-8.

4-7. 5-19. 4-24. E-3. 5-28. 9-25. 9-9. 8-31 INTERVAL YEAR TO MONTH 10-14 J Java C-4. 3-1. 10-10. 5-4. 5-24. 5-5. 7-22. 4-45. 7-9. 7-12. 3-32. 5-21. 5-8. 3-8. 3-3. 3-2. I-39 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 3-5. 3-13. 2-7. 3-30. 8-7. C-10. 4-10. 5-29. 3-17. 4-4. E-6. 3-29. 5-3. 5-3. 5-14. 5-22. 8-5. 4-5. 9-39. 3-27. 5-12. 7-9. 5-15. 8-25. 5-28. 5-2. 10-18 International Standards Organization I-31 INTERSECT Operator 8-3. 7-21 H HAVING Clause 5-2. 5-28. 7-25. 5-29. 7-12. 4-26. 4-6 IN Operator 2-11. 5-26. 3-11.5 Oracle University and TechnoLogica use only F . 4-14. 4-2. 5-29. 5-25. 10-8. 3-12. 5-15. E-16. 8-27. 7-21. C-23. 8-20. 3-31. 7-16. I-9. 5-13. 4-11. 5-11. 5-22. 9-6. 4-25. 8-4. 7-21. 10-27. 4-15. 3-10. 5-18. 7-9. 5-14. 5-19. 5-11. E-8. 7-21. 5-4. 5-3. E-12. 7-13. 5-16. E-15. 4-43 Functions 2-5. 3-7. 4-27. 5-20. I-4. 5-14. 10-23. 4-1. 5-27. 5-6. C-24. 10-36. 5-22. 4-19. 5-13. 9-8. 10-38. 4-21. 10-9. 5-23. 7-12. F-17. F-18 Index 10-4. 8-21. 5-20. 4-12. 4-23. 5-22. 8-30. I-5 Group Functions in a Subquery 7-3. 5-3. I-5 G GROUP BY Clause 5-2. 7-9. 10-22. 7-14 Group Functions 3-5. C-5. C-25. 5-13. 5-28. C-4. 3-18. 4-28. 5-19. 7-3. 9-19. 9-13. 5-5. 7-16. 5-26. 5-12. 4-3. 5-15. 5-7. 8-24. 9-42. 5-1. 8-18. 5-6. 9-12. 3-24. 3-20. C-8. 5-12. 3-30. 4-44. 4-9. 7-3. C-6. 5-25. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . 3-6. 3-28. 5-12. 10-10. 5-25. 4-20. 3-16. 5-2. 4-36. 8-19. 5-27. 7-5. I-12.Format Model 3-28. 8-12. 7-16. 3-33. 5-25. 7-25 I Implicit Data Type Conversion 4-4. 7-3. I-38 INSERT Statement 9-3. E-15. 3-14. 5-27. 7-25. 5-1. 3-9. E-14. 3-15. 5-20. 7-16. 4-16. 3-4. 5-26. 5-23. 4-20.

I-8. 7-12. 7-19 NULL Conditions 2-3. 6-12. I-10. 2-26. 6-23. 8-30. 10-32 NOT Operator 2-3. 10-15. F-22 NOT NULL Constraint 1-26. 8-24. 8-24. 2-7. 4-31. 5-8. 10-17. 5-5. 7-18. 5-3. 10-3. I-13. 8-27. 2-34. 10-18. 8-12. I-12. 3-13. 3-13. 5-25. 2-5. 3-32. 5-8. 7-6. C-30. 5-4. 4-11. D-17. D-6. 5-12. 3-10. 8-18. 2-18. D-15. 4-35. B-3. 3-33. 6-3. 8-18. 4-32. 5-25. 5-21. 7-24. 8-7. 10-21.J Joining Tables 6-6. B-2. 4-38. 4-31. 8-31 MOD Function 3-19 N Naming 10-3. F-23 K Keywords 1-5. 8-21. I-28. 8-27. 10-27 Nonequijoins 6-2. 2-14 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 5-23. 7-18. F-7. 10-18. 2-27. 10-26. 6-7. 3-21. I-40 MINUS Operator 8-3. I-34 MIN 1-8. 8-13. 10-17. 5-26. 5-28. 8-23. 10-31. 10-11. 6-9. F-8. 8-14. 6-7. 8-7. C-26. 5-7. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . 7-4. B-2. 4-32. 2-19. 7-17. 1-25. 10-12. 10-5. 10-37. 10-27. 10-34. 7-19. 3-13. 3-19. 8-23. I-16. 6-37. 10-6. 6-22. F-13. 1-22. 10-15. D-9. 10-25. I-15. 3-13 M MAX 5-3. 8-6. C-23. 1-14. I-4. F-14.6 Oracle University and TechnoLogica use only L . 8-22. C-25. 3-14. 9-31. 6-24. 8-12. 10-5. 8-16. D-4 LENGTH 3-9. 1-23. 9-20. 8-4. 1-16. 10-37 NEXTVAL 10-9. 6-19. 9-16. C-7. 8-22. F-9. 10-20. 1-8. 5-28. I-33. C-22. I-39. 4-42. 4-14. 10-34. 6-27. 8-31. I-36. 6-35. 6-8. 6-36. 5-5. F-15. 10-11. 10-7. 6-25. F-2. 5-7. 1-21. 8-3. I-27. I-20. 7-19. 10-9 LPAD 3-9. 2-12. 9-9. F-7. 8-26. B-3. 2-23. 10-14. 8-6. 8-17. 9-38. 1-19. C-8. 8-5. 2-38. 10-6. 2-13. I-3. 8-30. F-23. 2-22. 5-12. 5-14. 10-7. 8-21. 8-5. 3-23. F-8 LIKE Operator 2-12 Literal 1-3. 1-24. 10-31. 1-10. 6-37. 7-13. D-3. 7-14. 2-20. 1-30. 9-43. I-10. I-29. I-34.

1-14. D-3. I-2. 5-11. 7-3. 7-3. 3-28. 1-20. 1-10. 2-19. 10-14. 7-15. 5-12. C-4. 6-6. 9-33. 6-5. 5-3. 10-20. 10-5. I-3. I-32. 2-34. 10-23. I-40 ORDBMS I-2. 6-25. 4-36 NVL Function 4-29. 3-7. 2-14. 5-9. I-13. 1-25. 7-21. I-28 Null Values 1-3. 7-13. I-16 ON clause 6-3. 9-47. 5-9. C-4. 6-19. 4-3. 7-23. 4-4. 2-15. 6-24. 1-19. 8-6. 10-20. 7-25. 5-10. 1-10. I-39 Oracle Server 1-12. 4-10. 2-23. I-37. 9-43. F-8. I-29. 3-15. I-39 Oracle Enterprise Manager Grid Control I-13. 1-20. I-8. 1-25. 4-31. 5-10. 2-22. 2-24. 7-8. 9-38. 8-17 ON DELETE CASCADE 10-26 ON DELETE SET NULL 10-26 OR Operator 2-3. 2-13. 6-7. 4-29. 4-19. C-3. I-32. 8-19. 6-15. 4-28. I-16. 2-11. 9-4. I-15. I-33. 9-26. 1-16. F-15.7 Oracle University and TechnoLogica use only N . 2-23. 4-6. 5-6. I-4. 5-6. I-2. 10-9. 4-32. 8-13. 4-27. 1-14. 7-16. 6-27. 5-11. 5-22. 2-17. 4-30. F-18 Oracle Database 11g 3-24. 10-9.Null Value 1-3. 5-11 NVL2 Function 4-31 O Object Relational I-2. I-39 Oracle Fusion Middleware I-12. 3-27. 7-21. 10-38. 1-15. 6-17. 8-19. I-17 OLTP I-11. 9-8. 2-26. 2-24. 5-12. 7-23. 5-28. 5-25. I-36. 6-18. 8-13. 10-17. 8-4. 4-30. E-10 NULLIF Function 4-32 Number Functions 3-3. 3-16. 7-22. 4-23. 10-36. 9-32. 3-20. 10-22. 4-5. 7-9. 4-40. 1-16. I-39 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 7-22. I-11. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . D-13. 10-10. 7-17. 4-30. I-14. 7-16. 6-31. 1-19. 9-41. 10-16. 10-23. 3-8. 7-15. 4-28. I-10. I-16. 4-44. 6-21. 2-23. I-9. E-10. I-38. 1-15. 2-8. I-39 Oracle SQL Developer C-2. 6-8. 6-16. 4-33. 6-22. 4-38. 9-8. I-2. 5-3. 7-9. 9-8. 5-25. 4-20.

8-18. 8-26. 8-3. F-15. 2-32. 9-23. D-5. 8-13. 9-7. 7-20. 10-28. 5-28. 8-19. 8-19. 9-44. D-17. 8-15. 2-39. C-26. 7-4. 10-27. 9-43. 6-24. I-25. 10-13. 2-25. 6-30. 6-16. I-27 ORDER BY Clause 2-3. 8-25. 9-12. D-16. 3-6. 2-22. 5-17. 9-42 Read-only tables 10-3. 8-5. 8-2. 2-33. 10-31. I-27. 7-18. 2-23. 5-6. 8-21. 7-24. 10-27. C-29 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 9-39. 8-27. 1-24. 6-28. 9-8. 10-15. 3-6. 7-5. 7-23. 1-21. F-7. 6-14. 9-15. 7-16. 8-18. 5-15. 10-32. 5-15. 9-19. F-10. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . 2-25. 7-25. 8-5. 7-3. 9-47. 10-3. 2-34. 7-21. 2-3. 10-34. 8-6. 8-24. 6-26. 2-11. 10-34. 8-12. 10-6. I-30 R RDBMS 9-43. 8-20. 8-13. C-18. 9-17. 9-25. 8-5. 8-7. 2-19. I-39 Read Consistency 9-3. 7-19. 8-2. 4-21. 7-6. F-16. 8-29. 5-24. C-6. 6-29. 3-2. 2-24. 10-25. 8-27. 7-9. 2-26. 5-28. 5-18. 2-26. 5-15. 8-7. 9-33. 6-7. 8-28. 9-13. 8-24. C-27. 2-31. 9-40. 1-8. 10-33. F-8. 6-6. 8-6. 10-11. 1-17. 10-10. 10-40. 9-41. 8-21. 8-28. 8-30. 8-17. 2-23. D-14. 9-45. 2-2. F-19. 7-7. 9-31. 1-18. C-5. 2-38. 5-16. 10-11. I-22.8 Oracle University and TechnoLogica use only O Order 1-7. 10-13. 3-6. 2-25. 8-3. 10-26. 2-34. 10-37 REFERENCES 1-14. 5-14. 3-26. 7-14. 2-19. 7-22. I-18. 10-24. 8-29. 8-30. 10-31. 2-28. 7-12. D-3. 7-13. 2-28. 7-10. 2-27. I-14. 9-44. 5-16. 2-38. 10-41. 8-29. 2-24. 4-25. 10-15. 7-17. 9-43. 2-5. 10-6. 7-8. 8-4. 10-36. I-4. 3-33. C-10. 8-30. B-2. C-19. I-2. 2-33. 1-13. 10-37. 2-23. 8-12. D-15. 5-27. 10-20. 4-35. I-16. 10-19. 8-22. 8-17.P PRIMARY KEY Constraint 9-8. 5-22. 8-28. 10-13 . 2-20. 7-11. 7-26. 2-22. 2-39. 7-15. 5-18. D-13. 9-33. 10-23 Projection 1-4 Pseudocolumns 10-27 Q q operator 1-23 Query 1-4. 2-2.

5-20. 10-8. C-13. I-2. 8-4. 2-10. 2-25. 3-2. 9-42. 1-10. 9-41. 8-5. I-15. 10-28. D-16 ROUND and TRUNC Functions 3-30. 1-21. 9-13. 9-39. I-29. 5-15. 8-3. 8-24. I-28. 2-23. 1-19. 8-26. I-8. C-7. 2-24. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database:ISSQL Fundamentals I Index . C-3. 1-5. 9-25. 10-8 Set operators 8-1. 2-19. 2-34 S Schema 10-2. 2-9. I-15. I-4. 3-13 RR Date Format 3-22. 1-4. I-5 SET VERIFY ON 2-36 Sorting 2-1. 8-7. 2-32. 2-20. E-12 Self join 6-35 Sequences 2-24. 3-23. 9-47. 8-18. 5-17. 4-44. 3-13. 2-35. 1-25. 1-28. 6-2. 3-32 ROUND Function 3-17. I-3.9 Oracle University and TechnoLogica use only R . 8-3. 8-21. 9-43. 8-25. 8-27. 4-26 RPAD 3-9.Relational Database 9-43. 8-19. 8-12. 2-12. 9-19. 8-7. 1-7. I-29. 2-6. 8-24. 8-21. I-33. E-5. 2-22. 7-8. 10-32. 8-6. C-5. 2-4. 1-2. 7-2. I-8. 3-12. I-39 REPLACE 2-36. 7-10. 1-29. I-40 SELECT Statement 1-1. 9-22. 3-18. 9-3. F-7. I-4. 3-9. I-30. B-2. 8-22. 2-38. 2-26. 8-12. F-2. 10-18. 1-16. 8-31. 2-21. 6-7. 1-13. I-6. 8-18. 5-16. 2-34. I-4. 1-22. I-5 Selection 1-4. 2-21. 2-38. 5-19. 5-18. I-19. F-8. 1-3. 2-22. 4-22 Rules of Precedence 1-12. I-36. D-12. I-16. 7-5. I-5 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. I-2. 2-3. E-6. 2-39. 4-2. 5-9. I-31. C-10. I-36. 10-7. 9-44. 7-26. 2-26. 8-20. I-33. 2-39. I-27. 8-27. 7-25. 9-33. 2-19. D-2. 8-2. 10-5. 2-28. I-18. 2-3. I-3. I-34. 10-40. 7-11. 9-40. C-8. 8-6.

COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database: IS SQL Fundamentals I Index . 7-19. C-17. I-24 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 7-18. 2-31. 9-24. C-28. 1-8. 8-21. 4-20. 4-45. 4-10. 7-6. 8-27. 10-8. 9-29. 8-25. 10-34. 9-41. 4-17. 9-42. C-1. C-11. 3-13. 9-33. 6-16. 10-3. 4-18. 3-14. 9-34. 9-39. C-22. 7-10. C-4. 9-31. 7-25. 10-38. 8-31 UNIQUE Constraint 10-21. 9-26. 4-27. 10-4. 10-41. 10-37. 4-26. 4-25. 10-33. 7-17. 9-46. 9-21. 4-44 Transaction 9-2. C-27. C-25. 9-13. 3-24. 9-39. 7-12. 7-14. I-40 subquery 7-3. 4-27. C-13. 2-36. 7-22. 4-23. C-7. 9-31. 9-4. 7-8. 9-23. 7-18. 7-4. 2-32. C-31. 4-9. 4-22. C-26. 10-15. 7-9. 2-28. 9-47. 8-7. 3-10. C-10. I-11. I-24 SYSDATE Function 3-23. I-31 U UNION ALL 8-3. 9-19. C-5. 9-13. 4-21. 2-35. 2-26. C-2. 10-11. 9-12. 9-9 T TO_CHAR 4-2. C-9. 7-13.10 Oracle University and TechnoLogica use only S . 4-3. 1-26. 8-16. 10-40 Substitution Variables 2-3. 8-18. 2-22. 10-6. 4-8. 7-21. I-37. 4-3. 9-48. C-3. 4-11. 4-44. 8-6. 2-31. 8-12. 10-9. 4-44. 4-45. 9-25. 9-4. 7-11. 8-24. 10-31. 4-27. 2-38. 4-36. 9-3. 9-38. D-7. 3-30. 3-10. 9-17. 8-4. 7-20. 4-9. 8-26. 8-15. C-16 SUBSTR 3-9.SQL Developer 1-6. 4-9. 4-10. 4-36. 8-30. 4-8. 7-15. 4-23. 8-5. 7-24. 8-17. 9-32. 3-32. 4-10. 4-22. 4-3. 2-28. 3-28. C-6. 2-29. 4-25 Synonym 1-24. 3-18. 4-36. 8-14. 9-42. I-9. 10-13. I-2. 1-17. 4-19. 3-32. 9-30. 4-21. 10-22 Unique Identifier I-23. C-30. 9-19. I-31 TRIM 3-9. C-29. 2-39. 9-10 TO_NUMBER 4-2. 4-43. 9-25. 4-23. 2-36. 4-16. 2-34. 4-7. 2-19. 4-42. 7-7. C-23. 4-7. 7-23. I-32. 10-32. 9-3. 8-25 TO_DATE 4-2. 9-32. 4-34. I-23. 1-14. 9-43. 8-29. 7-16. C-16. 2-27. 3-13 TRUNC 3-16. 4-7. 9-27. 9-27. 1-26. 2-33. 2-30. 1-9. 9-15. 10-38. F-10. 4-20. 9-11. 7-5. 4-8. 8-30 UNION Operator 8-13. I-7.

9-16. E-3. 9-15. F-21. 6-8. 5-28 VERIFY Command 2-3. 9-13. 6-11. 7-15. 9-39. 6-15. 6-36. 5-27. C-26. 6-22. 9-19. 9-42. 2-32. 7-23. 5-8. 2-36 Views 10-8. C-27. 2-9. 2-28. 3-12. 9-18. 9-17. 2-34. I-39 THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. 2-22. 2-11. 9-43. C-10. 6-17. 7-5. 6-18. I-14. 2-34. 2-31. 2-5. I-9. 6-10. 6-14. 2-26. 2-19. 7-14. 9-25. 6-5. E-13 W WHERE Clause 2-3. 10-38. 9-15. C-30. 9-22. 2-4. 5-21. 6-13. 5-22. 7-2. C-24 VARIANCE 5-5. 5-28. 8-5. 6-19. 2-39. 10-36 USING Clause 6-3. 2-6. 2-15. 5-15. 2-37. 2-26. 10-10. F-12. F-10.11 Oracle University and TechnoLogica use only V . 2-7. F-17. 7-13. 6-31 Using Snippets C-23. 5-18. 5-9. E-12. 2-19. 5-14. 2-38. E-6. 9-16. 5-20. 2-8. F-22 X XML C-7. F-7. 6-14. F-4. 6-25. 2-27.U UPDATE Statement 9-3. 2-22. C-9. COPYING eKIT MATERIALS FROM THIS STRICTLY PROHIBITED OracleCOMPUTER Database: IS SQL Fundamentals I Index .

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED .Oracle University and TechnoLogica use only THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.