0% found this document useful (0 votes)
93 views

Oracle Database 12c: SQL Workshop I: Chapter 1: Introduction

This document is the contents page for a training manual on Oracle Database 12c: SQL Workshop I. It includes chapter summaries and lesson objectives for material on retrieving data using the SQL SELECT statement, restricting and sorting data with the WHERE clause, and character strings and dates. Key topics covered include the basic SELECT statement, selecting specific columns, arithmetic expressions, null values, column aliases, concatenation, and using the DESCRIBE command to view table structures. Quizzes and practices are also included at the end of chapters.

Uploaded by

Apdev Option
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views

Oracle Database 12c: SQL Workshop I: Chapter 1: Introduction

This document is the contents page for a training manual on Oracle Database 12c: SQL Workshop I. It includes chapter summaries and lesson objectives for material on retrieving data using the SQL SELECT statement, restricting and sorting data with the WHERE clause, and character strings and dates. Key topics covered include the basic SELECT statement, selecting specific columns, arithmetic expressions, null values, column aliases, concatenation, and using the DESCRIBE command to view table structures. Quizzes and practices are also included at the end of chapters.

Uploaded by

Apdev Option
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 19

Contents

O r a c l e D a t a b a s e 1 2 c : S q l Wo r k s h o p I

Chapter 1: Introduction
Lesson Objectives...................................................................................................................... 1-2
Lesson Agenda........................................................................................................................... 1-3
Course Objectives...................................................................................................................... 1-4
Course Agenda........................................................................................................................... 1-5
Appendixes and Practices Used in the Course........................................................................... 1-7
Lesson Agenda........................................................................................................................... 1-8
Oracle Database 12c: Focus Areas............................................................................................. 1-9
Oracle Database 12c.................................................................................................................. 1-10
Oracle Fusion Middleware......................................................................................................... 1-12
Oracle Cloud.............................................................................................................................. 1-14
Oracle Cloud Services............................................................................................................... 1-15
Cloud Deployment Models........................................................................................................ 1-16
Lesson Agenda........................................................................................................................... 1-17
Relational and Object Relational Database Management Systems........................................... 1-18
Data Storage on Different Media............................................................................................... 1-19
Relational Database Concept..................................................................................................... 1-20
Definition of a Relational Database........................................................................................... 1-21
Data Models............................................................................................................................... 1-22
Entity Relationship Model......................................................................................................... 1-23
Entity Relationship Modeling Conventions............................................................................... 1-25
Relating Multiple Tables............................................................................................................ 1-27
Relational Database Terminology.............................................................................................. 1-29
Lesson Agenda........................................................................................................................... 1-31
Using SQL to Query Your Database.......................................................................................... 1-32
SQL Statements Used in the Course.......................................................................................... 1-33
Development Environments for SQL........................................................................................ 1-34
Lesson Agenda........................................................................................................................... 1-35

i
Human Resources (HR) Schema............................................................................................... 1-36
Tables Used in the Course.......................................................................................................... 1-37
Lesson Agenda........................................................................................................................... 1-38
Oracle Database Documentation................................................................................................ 1-39
Additional Resources................................................................................................................. 1-40
Summary.................................................................................................................................... 1-41
Practice 1: Overview.................................................................................................................. 1-42

Chapter 2: Retrieving Data Using the SQL SELECT Statement


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

Chapter 3: Restricting and Sorting Data


Objectives.................................................................................................................................. 3-2
Lesson Agenda........................................................................................................................... 3-3
Limiting Rows by Using a Selection......................................................................................... 3-4
Limiting Rows That Are Selected.............................................................................................. 35
Using the WHERE Clause......................................................................................................... 3-6
Character Strings and Dates....................................................................................................... 3-7
Comparison Operators............................................................................................................... 3-8
Using Comparison Operators..................................................................................................... 3-9
Range Conditions Using the BETWEEN Operator................................................................... 3-10
Using the IN Operator................................................................................................................ 3-11
Pattern Matching Using the LIKE Operator.............................................................................. 3-12
Combining Wildcard Characters................................................................................................ 3-13
Using NULL Conditions............................................................................................................ 3-14
Defining Conditions Using Logical Operators.......................................................................... 3-15
Using the AND Operator........................................................................................................... 3-16
Using the OR Operator.............................................................................................................. 3-17
Using the NOT Operator............................................................................................................ 3-18
Lesson Agenda........................................................................................................................... 3-19
Rules of Precedence................................................................................................................... 3-20
Lesson Agenda........................................................................................................................... 3-22
Using the ORDER BY Clause................................................................................................... 3-23
Sorting........................................................................................................................................ 3-24
Lesson Agenda........................................................................................................................... 3-26
SQL Row Limiting Clause......................................................................................................... 3-27
Using SQL Row Limiting Clause in a Query............................................................................ 3-28
SQL Row Limiting Clause: Example........................................................................................ 3-29
Lesson Agenda........................................................................................................................... 3-30
Substitution Variables................................................................................................................ 3-31
Using the Single-Ampersand Substitution Variable.................................................................. 3-33
Character and Date Values with Substitution Variables............................................................. 3-35
Specifying Column Names, Expressions, and Text................................................................... 3-36
iii
Using the Double-Ampersand Substitution Variable................................................................. 3-37
Using the Ampersand Substitution Variable in SQL*Plus......................................................... 3-38
Lesson Agenda........................................................................................................................... 3-39
Using the DEFINE Command................................................................................................... 3-40
Using the VERIFY Command................................................................................................... 3-41
Quiz............................................................................................................................................ 3-42
Summary.................................................................................................................................... 3-43
Practice 3: Overview.................................................................................................................. 3-44

Chapter 4: Using Single-Row Functions to Customize Output


Objectives.................................................................................................................................. 4-2
Lesson Agenda........................................................................................................................... 4-3
SQL Functions........................................................................................................................... 4-4
Two Types of SQL Functions.................................................................................................... 4-5
Single-Row Functions................................................................................................................ 4-6
Lesson Agenda........................................................................................................................... 4-8
Character Functions................................................................................................................... 4-9
Case-Conversion Functions....................................................................................................... 4-11
Using Case-Conversion Functions............................................................................................. 4-12
Character-Manipulation Functions............................................................................................ 4-13
Using Character-Manipulation Functions.................................................................................. 4-14
Lesson Agenda........................................................................................................................... 4-15
Nesting Functions...................................................................................................................... 4-16
Nesting Functions: Example...................................................................................................... 4-17
Lesson Agenda........................................................................................................................... 4-18
Numeric Functions..................................................................................................................... 4-19
Using the ROUND Function...................................................................................................... 4-20
Using the TRUNC Function...................................................................................................... 4-21
Using the MOD Function.......................................................................................................... 4-22
Lesson Agenda........................................................................................................................... 4-23
Working with Dates................................................................................................................... 4-24
RR Date Format......................................................................................................................... 4-25
Using the SYSDATE Function.................................................................................................. 4-27
Using the CURRENT_DATE and CURRENT_TIMESTAMP Functions................................ 4-28
Arithmetic with Dates................................................................................................................ 4-29
iv
Using Arithmetic Operators with Dates..................................................................................... 4-30
Lesson Agenda........................................................................................................................... 4-31
Date-Manipulation Functions.................................................................................................... 4-32
Using Date Functions................................................................................................................. 4-33
Using ROUND and TRUNC Functions with Dates.................................................................. 4-34
Quiz............................................................................................................................................ 4-35
Summary.................................................................................................................................... 4-36
Practice 4: Overview.................................................................................................................. 4-37

Chapter 5: Using Conversion Functions and Conditional Expressions


Objectives.................................................................................................................................. 5-2
Lesson Agenda........................................................................................................................... 5-3
Conversion Functions................................................................................................................ 5-4
Implicit Data Type Conversion.................................................................................................. 5-5
Explicit Data Type Conversion.................................................................................................. 5-7
Lesson Agenda........................................................................................................................... 5-9
Using the TO_CHAR Function with Dates............................................................................... 5-10
Elements of the Date Format Model.......................................................................................... 5-11
Using the TO_CHAR Function with Dates............................................................................... 5-14
Using the TO_CHAR Function with Numbers.......................................................................... 5-15
Using the TO_NUMBER and TO_DATE Functions................................................................. 5-18
Using TO_CHAR and TO_DATE Functions with the RR Date Format................................... 5-20
Lesson Agenda........................................................................................................................... 5-21
General Functions...................................................................................................................... 5-22
NVL Function............................................................................................................................ 5-23
Using the NVL Function............................................................................................................ 5-24
Using the NVL2 Function.......................................................................................................... 5-25
Using the NULLIF Function...................................................................................................... 5-26
Using the COALESCE Function............................................................................................... 5-27
Lesson Agenda........................................................................................................................... 5-29
Conditional Expressions............................................................................................................ 5-30
CASE Expression...................................................................................................................... 5-31
Using the CASE Expression...................................................................................................... 5-32
Searched CASE Expression....................................................................................................... 5-33
DECODE Function.................................................................................................................... 5-34
v
Using the DECODE Function.................................................................................................... 5-35
Quiz............................................................................................................................................ 5-37
Summary.................................................................................................................................... 5-38
Practice 5: Overview.................................................................................................................. 5-39

Chapter 6: Reporting Aggregated Data Using the Group Functions


Objectives.................................................................................................................................. 6-2
Lesson Agenda........................................................................................................................... 6-3
Group Functions........................................................................................................................ 6-4
Types of Group Functions.......................................................................................................... 6-5
Group Functions: Syntax........................................................................................................... 6-6
Using the AVG and SUM Functions.......................................................................................... 6-7
Using the MIN and MAX Functions......................................................................................... 6-8
Using the COUNT Function...................................................................................................... 6-9
Using the DISTINCT Keyword................................................................................................. 6-10
Group Functions and Null Values.............................................................................................. 6-11
Lesson Agenda........................................................................................................................... 6-12
Creating Groups of Data............................................................................................................ 6-13
Creating Groups of Data: GROUP BY Clause Syntax.............................................................. 6-14
Using the GROUP BY Clause................................................................................................... 6-15
Grouping by More Than One Column....................................................................................... 6-17
Using the GROUP BY Clause on Multiple Columns................................................................ 6-18
Illegal Queries Using Group Functions..................................................................................... 6-19
Restricting Group Results.......................................................................................................... 6-21
Restricting Group Results with the HAVING Clause................................................................ 6-22
Using the HAVING Clause........................................................................................................ 6-23
Lesson Agenda........................................................................................................................... 6-25
Nesting Group Functions........................................................................................................... 6-26
Quiz............................................................................................................................................ 6-27
Summary.................................................................................................................................... 6-28
Practice 6: Overview.................................................................................................................. 6-29

Chapter 7: Displaying Data from Multiple Tables Using Joins


Objectives.................................................................................................................................. 7-2
Lesson Agenda........................................................................................................................... 7-3
vi
Obtaining Data from Multiple Tables........................................................................................ 7-4
Types of Joins............................................................................................................................ 7-5
Joining Tables Using SQL:1999 Syntax.................................................................................... 7-6
Lesson Agenda........................................................................................................................... 7-7
Creating Natural Joins............................................................................................................... 7-8
Retrieving Records with Natural Joins...................................................................................... 7-9
Creating Joins with the USING Clause..................................................................................... 7-10
Joining Column Names.............................................................................................................. 7-11
Retrieving Records with the USING Clause............................................................................. 7-12
Qualifying Ambiguous Column Names..................................................................................... 7-13
Using Table Aliases with the USING Clause............................................................................. 7-14
Creating Joins with the ON Clause............................................................................................ 7-15
Retrieving Records with the ON Clause.................................................................................... 7-16
Creating Three-Way Joins.......................................................................................................... 7-17
Applying Additional Conditions to a Join................................................................................. 7-18
Lesson Agenda........................................................................................................................... 7-19
Joining a Table to Itself.............................................................................................................. 7-20
Self-Joins Using the ON Clause................................................................................................ 7-21
Lesson Agenda........................................................................................................................... 7-22
Nonequijoins.............................................................................................................................. 7-23
Retrieving Records with Nonequijoins...................................................................................... 7-24
Lesson Agenda........................................................................................................................... 7-25
Returning Records with No Direct Match Using OUTER Joins............................................... 7-26
INNER Versus OUTER Joins.................................................................................................... 7-27
LEFT OUTER JOIN.................................................................................................................. 7-28
RIGHT OUTER JOIN............................................................................................................... 7-29
FULL OUTER JOIN.................................................................................................................. 7-30
Lesson Agenda........................................................................................................................... 7-31
Cartesian Products..................................................................................................................... 7-32
Generating a Cartesian Product................................................................................................. 7-33
Creating Cross Joins.................................................................................................................. 7-34
Quiz............................................................................................................................................ 7-35
Summary.................................................................................................................................... 7-36
Practice 7: Overview.................................................................................................................. 7-37

vii
Chapter 8: Using Subqueries to Solve Queries
Objectives.................................................................................................................................. 8-2
Lesson Agenda........................................................................................................................... 8-3
Using a Subquery to Solve a Problem....................................................................................... 8-4
Subquery Syntax........................................................................................................................ 8-5
Using a Subquery....................................................................................................................... 8-6
Rules and Guidelines for Using Subqueries.............................................................................. 8-7
Types of Subqueries................................................................................................................... 8-8
Lesson Agenda........................................................................................................................... 8-9
Single-Row Subqueries.............................................................................................................. 8-10
Executing Single-Row Subqueries............................................................................................ 8-11
Using Group Functions in a Subquery....................................................................................... 8-12
HAVING Clause with Subqueries............................................................................................. 8-13
What Is Wrong with This Statement?........................................................................................ 8-14
No Rows Returned by the Inner Query..................................................................................... 8-15
Lesson Agenda........................................................................................................................... 8-16
Multiple-Row Subqueries.......................................................................................................... 8-17
Using the ANY Operator in Multiple-Row Subqueries............................................................. 8-18
Using the ALL Operator in Multiple-Row Subqueries.............................................................. 8-19
Multiple-Column Subqueries..................................................................................................... 8-20
Multiple-Column Subquery: Example....................................................................................... 8-21
Lesson Agenda........................................................................................................................... 8-22
Null Values in a Subquery.......................................................................................................... 8-23
Quiz............................................................................................................................................ 8-25
Summary.................................................................................................................................... 8-26
Practice 8: Overview.................................................................................................................. 8-27

Chapter 9: Using the Set Operators


Objectives.................................................................................................................................. 9-2
Lesson Agenda........................................................................................................................... 9-3
Set Operators.............................................................................................................................. 9-4
Set Operator Rules..................................................................................................................... 9-5
Oracle Server and Set Operators................................................................................................ 9-6
Lesson Agenda........................................................................................................................... 9-7
viii
Tables Used in This Lesson....................................................................................................... 9-8
Lesson Agenda........................................................................................................................... 9-12
UNION Operator....................................................................................................................... 9-13
Using the UNION Operator....................................................................................................... 9-14
UNION ALL Operator............................................................................................................... 9-15
Using the UNION ALL Operator............................................................................................... 9-16
Lesson Agenda........................................................................................................................... 9-17
INTERSECT Operator............................................................................................................... 9-18
Using the INTERSECT Operator.............................................................................................. 9-19
Lesson Agenda........................................................................................................................... 9-20
MINUS Operator....................................................................................................................... 9-21
Using the MINUS Operator....................................................................................................... 9-22
Lesson Agenda........................................................................................................................... 9-23
Matching SELECT Statements.................................................................................................. 9-24
Matching the SELECT Statement: Example............................................................................. 9-25
Lesson Agenda........................................................................................................................... 9-26
Using the ORDER BY Clause in Set Operations...................................................................... 9-27
Summary.................................................................................................................................... 9-28
Practice 9: Overview.................................................................................................................. 9-29

Chapter 10: Managing Tables Using DML Statements


Objectives.................................................................................................................................. 10-2
Lesson Agenda........................................................................................................................... 10-3
Data Manipulation Language..................................................................................................... 10-4
Adding a New Row to a Table................................................................................................... 10-5
INSERT Statement Syntax......................................................................................................... 10-6
Inserting New Rows................................................................................................................... 10-7
Inserting Rows with Null Values............................................................................................... 10-8
Inserting Special Values............................................................................................................. 10-9
Inserting Specific Date and Time Values................................................................................... 10-10
Creating a Script........................................................................................................................ 10-11
Copying Rows from Another Table........................................................................................... 10-12
Lesson Agenda........................................................................................................................... 10-13
Changing Data in a Table........................................................................................................... 10-14
UPDATE Statement Syntax....................................................................................................... 10-15
ix
Updating Rows in a Table.......................................................................................................... 10-16
Updating Two Columns with a Subquery.................................................................................. 10-1
Updating Rows Based on Another Table................................................................................... 10-18
Lesson Agenda........................................................................................................................... 10-19
Removing a Row from a Table.................................................................................................. 10-20
DELETE Statement................................................................................................................... 10-21
Deleting Rows from a Table...................................................................................................... 10-22
Deleting Rows Based on Another Table.................................................................................... 10-23
TRUNCATE Statement.............................................................................................................. 10-24
Lesson Agenda........................................................................................................................... 10-25
Database Transactions................................................................................................................ 10-26
Database Transactions: Start and End........................................................................................ 10-27
Advantages of COMMIT and ROLLBACK Statements........................................................... 10-28
Explicit Transaction Control Statements................................................................................... 10-29
Rolling Back Changes to a Marker............................................................................................ 10-30
Implicit Transaction Processing................................................................................................. 10-31
State of Data Before COMMIT or ROLLBACK...................................................................... 10-33
State of Data After COMMIT.................................................................................................... 10-34
Committing Data........................................................................................................................ 10-35
State of Data After ROLLBACK............................................................................................... 10-36
State of Data After ROLLBACK: Example............................................................................... 10-37
Statement-Level Rollback.......................................................................................................... 10-38
Lesson Agenda........................................................................................................................... 10-39
Read Consistency....................................................................................................................... 10-40
Implementing Read Consistency............................................................................................... 10-41
Lesson Agenda........................................................................................................................... 10-42
FOR UPDATE Clause in a SELECT Statement........................................................................ 10-43
FOR UPDATE Clause: Examples.............................................................................................. 10-44
Quiz............................................................................................................................................ 10-46
Summary.................................................................................................................................... 10-47
Practice 10: Overview................................................................................................................ 10-48

Chapter 11: Introduction to Data Definition Language


Objectives.................................................................................................................................. 11-2
Lesson Agenda........................................................................................................................... 11-3
x
Database Objects........................................................................................................................ 11-4
Naming Rules............................................................................................................................ 11-5
Lesson Agenda........................................................................................................................... 11-6
CREATE TABLE Statement...................................................................................................... 11-7
Creating Tables.......................................................................................................................... 11-8
Lesson Agenda........................................................................................................................... 11-9
Datetime Data Types.................................................................................................................. 11-12
DEFAULT Option...................................................................................................................... 11-13
Lesson Agenda........................................................................................................................... 11-14
Including Constraints................................................................................................................. 11-15
Constraint Guidelines................................................................................................................ 11-16
Defining Constraints.................................................................................................................. 11-17
NOT NULL Constraint.............................................................................................................. 11-19
UNIQUE Constraint.................................................................................................................. 11-20
PRIMARY KEY Constraint....................................................................................................... 11-22
FOREIGN KEY Constraint....................................................................................................... 11-23
FOREIGN KEY Constraint: Keywords..................................................................................... 11-25
CHECK Constraint.................................................................................................................... 11-26
CREATE TABLE: Example....................................................................................................... 11-27
Violating Constraints................................................................................................................. 11-28
Lesson Agenda........................................................................................................................... 11-30
Creating a Table Using a Subquery............................................................................................ 11-31
Lesson Agenda........................................................................................................................... 11-33
ALTER TABLE Statement........................................................................................................ 11-34
Adding a Column....................................................................................................................... 11-36
Modifying a Column.................................................................................................................. 11-37
Dropping a Column................................................................................................................... 11-38
SET UNUSED Option............................................................................................................... 11-39
Read-Only Tables....................................................................................................................... 11-41
Lesson Agenda........................................................................................................................... 11-42
Dropping a Table........................................................................................................................ 11-43
Quiz............................................................................................................................................ 11-44
Summary.................................................................................................................................... 11-45
Practice 11: Overview................................................................................................................ 11-46

xi
O r a c l e D a t a b a s e 1 2 c : S q l Wo r k s h o p I I

Chapter 1: Introduction
Lesson Objectives...................................................................................................................... 1-2
Lesson Agenda........................................................................................................................... 1-3
Course Objectives...................................................................................................................... 1-4
Course Prerequisites.................................................................................................................. 1-5
Course Agenda........................................................................................................................... 1-6
Lesson Agenda........................................................................................................................... 1-7
Tables Used in This Course....................................................................................................... 1-8
Appendixes and Practices Used in This Course........................................................................ 1-10
Development Environments...................................................................................................... 1-11
Lesson Agenda........................................................................................................................... 1-12
Review of Restricting Data........................................................................................................ 1-13
Review of Sorting Data.............................................................................................................. 1-14
Review of SQL Functions.......................................................................................................... 1-15
Review of Single-Row Functions.............................................................................................. 1-16
Review of Types of Group Functions........................................................................................ 1-17
Review of Using Subqueries...................................................................................................... 1-18
Review of Managing Tables Using DML Statements................................................................ 1-20
Lesson Agenda........................................................................................................................... 1-22
Oracle Database SQL Documentation....................................................................................... 1-23
Additional Resources................................................................................................................. 1-24
Summary.................................................................................................................................... 1-25
Practice 1: Overview.................................................................................................................. 1-26

Chapter 2: Introduction to Data Dictionary Views


Objectives.................................................................................................................................. 2-2
Lesson Agenda........................................................................................................................... 2-3
Data Dictionary.......................................................................................................................... 2-4
Data Dictionary Structure.......................................................................................................... 2-5
How to Use the Dictionary Views............................................................................................. 2-7
USER_OBJECTS and ALL_OBJECTS Views......................................................................... 2-8
USER_OBJECTS View............................................................................................................. 2-9

xii
Lesson Agenda........................................................................................................................... 2-10
Table Information....................................................................................................................... 2-11
Column Information.................................................................................................................. 2-12
Constraint Information............................................................................................................... 2-14
USER_CONSTRAINTS: Example........................................................................................... 2-15
Querying USER_CONS_COLUMNS....................................................................................... 2-16
Lesson Agenda........................................................................................................................... 2-17
Adding Comments to a Table..................................................................................................... 2-18
Quiz............................................................................................................................................ 2-19
Summary.................................................................................................................................... 2-20
Practice 2: Overview.................................................................................................................. 2-21

Chapter 3: Creating Sequences, Synonyms, and Indexes


Objectives.................................................................................................................................. 3-2
Lesson Agenda........................................................................................................................... 3-3
Database Objects........................................................................................................................ 3-4
Referencing Another User’s Tables........................................................................................... 3-5
Sequences................................................................................................................................... 3-6
CREATE SEQUENCE Statement: Syntax................................................................................ 3-7
Creating a Sequence................................................................................................................... 3-9
NEXTVAL and CURRVAL Pseudocolumns............................................................................. 3-10
Using a Sequence....................................................................................................................... 3-12
SQL Column Defaulting Using a Sequence.............................................................................. 3-13
Caching Sequence Values.......................................................................................................... 3-14
Modifying a Sequence............................................................................................................... 3-15
Guidelines for Modifying a Sequence....................................................................................... 3-16
Sequence Information................................................................................................................ 3-17
Lesson Agenda........................................................................................................................... 3-18
Synonyms................................................................................................................................... 3-19
Creating a Synonym for an Object............................................................................................ 3-20
Creating and Removing Synonyms........................................................................................... 3-21
Synonym Information................................................................................................................ 3-22
Lesson Agenda........................................................................................................................... 3-23
Indexes....................................................................................................................................... 3-24
How Are Indexes Created?........................................................................................................ 3-25

xiii
Creating an Index....................................................................................................................... 3-26
CREATE INDEX with the CREATE TABLE Statement.......................................................... 3-27
Function-Based Indexes............................................................................................................. 3-29
Creating Multiple Indexes on the Same Set of Columns........................................................... 3-30
Example of Creating Multiple Indexes on the Same Set of Columns....................................... 3-31
Index Information...................................................................................................................... 3-32
USER_INDEXES: Examples.................................................................................................... 3-33
Querying USER_IND_COLUMNS.......................................................................................... 3-34
Removing an Index.................................................................................................................... 3-35
Quiz............................................................................................................................................ 3-36
Summary.................................................................................................................................... 3-37
Practice 3: Overview.................................................................................................................. 3-38

Chapter 4: Creating Views


Objectives.................................................................................................................................. 4-2
Lesson Agenda........................................................................................................................... 4-3
Database Objects........................................................................................................................ 4-4
What Is a View?......................................................................................................................... 4-5
Advantages of Views................................................................................................................. 4-6
Simple Views and Complex Views............................................................................................ 4-7
Lesson Agenda........................................................................................................................... 4-8
Creating a View.......................................................................................................................... 4-9
Retrieving Data from a View..................................................................................................... 4-12
Modifying a View...................................................................................................................... 4-13
Creating a Complex View.......................................................................................................... 4-14
View Information....................................................................................................................... 4-15
Lesson Agenda........................................................................................................................... 4-16
Rules for Performing DML Operations on a View.................................................................... 4-17
Using the WITH CHECK OPTION Clause............................................................................... 4-20
Denying DML Operations......................................................................................................... 4-21
Lesson Agenda........................................................................................................................... 4-22
Removing a View....................................................................................................................... 4-24
Quiz............................................................................................................................................ 4-25
Summary.................................................................................................................................... 4-26
Practice 4: Overview.................................................................................................................. 4-27

xiv
Chapter 5: Managing Schema Objects
Objectives.................................................................................................................................. 5-2
Lesson Agenda........................................................................................................................... 5-3
Adding a Constraint Syntax....................................................................................................... 5-4
Adding a Constraint................................................................................................................... 5-5
Dropping a Constraint................................................................................................................ 5-6
Dropping a CONSTRAINT ONLINE....................................................................................... 5-7
ON DELETE Clause.................................................................................................................. 5-8
Cascading Constraints................................................................................................................ 5-9
Renaming Table Columns and Constraints................................................................................ 5-11
Disabling Constraints................................................................................................................. 5-12
Enabling Constraints.................................................................................................................. 5-13
Constraint States........................................................................................................................ 5-14
Deferring Constraints................................................................................................................. 5-15
Difference Between INITIALLY DEFERRED and INITIALLY IMMEDIATE....................... 5-16
DROP TABLE … PURGE........................................................................................................ 5-18
Lesson Agenda........................................................................................................................... 5-19
Temporary Tables....................................................................................................................... 5-20
Creating a Temporary Table....................................................................................................... 5-21
Lesson Agenda........................................................................................................................... 5-22
External Tables........................................................................................................................... 5-23
Creating a Directory for the External Table............................................................................... 5-24
Creating an External Table......................................................................................................... 5-26
Creating an External Table by Using ORACLE_LOADER...................................................... 5-28
Querying External Tables........................................................................................................... 5-30
Creating an External Table by Using ORACLE_DATAPUMP: Example................................. 5-31
Quiz............................................................................................................................................ 5-32
Summary.................................................................................................................................... 5-33
Practice 5: Overview.................................................................................................................. 5-34

Chapter 6: Retrieving Data by Using Subqueries


Objectives.................................................................................................................................. 6-2
Lesson Agenda........................................................................................................................... 6-3
Retrieving Data by Using a Subquery as a Source.................................................................... 6-4
xv
Lesson Agenda........................................................................................................................... 6-6
Multiple-Column Subqueries..................................................................................................... 6-7
Column Comparisons................................................................................................................ 6-8
Pairwise Comparison Subquery................................................................................................. 6-9
Nonpairwise Comparison Subquery.......................................................................................... 6-10
Lesson Agenda........................................................................................................................... 6-11
Scalar Subquery Expressions..................................................................................................... 6-12
Scalar Subqueries: Examples..................................................................................................... 6-13
Lesson Agenda........................................................................................................................... 6-14
Correlated Subqueries................................................................................................................ 6-15
Using Correlated Subqueries: Example 1.................................................................................. 6-17
Using Correlated Subqueries: Example 2.................................................................................. 6-18
Lesson Agenda........................................................................................................................... 6-19
Using the EXISTS Operator...................................................................................................... 6-20
Find All Departments That Do Not Have Any Employees........................................................ 6-22
Lesson Agenda........................................................................................................................... 6-23
WITH Clause............................................................................................................................. 6-24
WITH Clause: Example............................................................................................................. 6-25
Recursive WITH Clause............................................................................................................ 6-26
Recursive WITH Clause: Example............................................................................................ 6-27
Quiz............................................................................................................................................ 6-28
Summary.................................................................................................................................... 6-29
Practice 6: Overview.................................................................................................................. 6-30

Chapter 7: Manipulating Data by Using Subqueries


Objectives.................................................................................................................................. 7-2
Lesson Agenda........................................................................................................................... 7-3
Using Subqueries to Manipulate Data....................................................................................... 7-4
Lesson Agenda........................................................................................................................... 7-5
Inserting by Using a Subquery as a Target................................................................................ 7-6
Lesson Agenda........................................................................................................................... 7-8
Using the WITH CHECK OPTION Keyword on DML Statements......................................... 7-9
Lesson Agenda........................................................................................................................... 7-11
Correlated UPDATE.................................................................................................................. 7-12
Using Correlated UPDATE........................................................................................................ 7-13

xvi
Correlated DELETE.................................................................................................................. 7-15
Using Correlated DELETE........................................................................................................ 7-16
Summary.................................................................................................................................... 7-17
Practice 7: Overview.................................................................................................................. 7-18

Chapter 8: Controlling User Access


Objectives.................................................................................................................................. 8-2
Lesson Agenda........................................................................................................................... 8-3
Controlling User Access............................................................................................................ 8-4
Privileges................................................................................................................................... 8-5
System Privileges....................................................................................................................... 8-6
Creating Users............................................................................................................................ 8-7
User System Privileges.............................................................................................................. 8-8
Granting System Privileges....................................................................................................... 8-10
Lesson Agenda........................................................................................................................... 8-11
What Is a Role?.......................................................................................................................... 8-12
Creating and Granting Privileges to a Role............................................................................... 8-13
Changing Your Password........................................................................................................... 8-14
Lesson Agenda........................................................................................................................... 8-15
Object Privileges........................................................................................................................ 8-16
Granting Object Privileges......................................................................................................... 8-18
Passing On Your Privileges........................................................................................................ 8-19
Confirming Granted Privileges.................................................................................................. 8-20
Lesson Agenda........................................................................................................................... 8-21
Revoking Object Privileges....................................................................................................... 8-22
Quiz............................................................................................................................................ 8-24
Summary.................................................................................................................................... 8-25
Practice 8: Overview.................................................................................................................. 8-26

Chapter 9: Manipulating Data


Objectives.................................................................................................................................. 9-2
Lesson Agenda........................................................................................................................... 9-3
Explicit Default Feature: Overview........................................................................................... 9-4
Using Explicit Default Values.................................................................................................... 9-5
Lesson Agenda........................................................................................................................... 9-6
xvii
Multitable INSERT Statements: Overview................................................................................ 9-7
Types of Multitable INSERT Statements................................................................................... 9-9
Multitable INSERT Statements.................................................................................................. 9-10
Unconditional INSERT ALL..................................................................................................... 9-12
Conditional INSERT ALL: Example......................................................................................... 9-13
Conditional INSERT ALL......................................................................................................... 9-14
Conditional INSERT FIRST: Example...................................................................................... 9-16
Conditional INSERT FIRST...................................................................................................... 9-17
Pivoting INSERT....................................................................................................................... 9-19
Lesson Agenda........................................................................................................................... 9-22
MERGE Statement.................................................................................................................... 9-23
MERGE Statement Syntax........................................................................................................ 9-24
Merging Rows: Example........................................................................................................... 9-25
Lesson Agenda........................................................................................................................... 9-28
FLASHBACK TABLE Statement............................................................................................. 9-29
Using the FLASHBACK TABLE Statement............................................................................. 9-31
Lesson Agenda........................................................................................................................... 9-32
Tracking Changes in Data.......................................................................................................... 9-33
Flashback Query: Example........................................................................................................ 9-34
Flashback Version Query: Example........................................................................................... 9-35
VERSIONS BETWEEN Clause................................................................................................ 9-36
Quiz............................................................................................................................................ 9-37
Summary.................................................................................................................................... 9-39
Practice 9: Overview.................................................................................................................. 9-40

Chapter 10: Managing Data in Different Time Zones


Objectives.................................................................................................................................. 10-2
Lesson Agenda........................................................................................................................... 10-3
Time Zones................................................................................................................................ 10-4
TIME_ZONE Session Parameter............................................................................................... 10-5
CURRENT_DATE, CURRENT_TIMESTAMP, and LOCALTIMESTAMP........................... 10-6
Comparing Date and Time in a Session’s Time Zone................................................................ 10-7
DBTIMEZONE and SESSIONTIMEZONE............................................................................. 10-9
TIMESTAMP Data Types.......................................................................................................... 10-10
TIMESTAMP Fields.................................................................................................................. 10-11

xviii
Difference Between DATE and TIMESTAMP.......................................................................... 10-12
Comparing TIMESTAMP Data Types....................................................................................... 10-13
Lesson Agenda........................................................................................................................... 10-14
INTERVAL Data Types.............................................................................................................. 10-15
INTERVAL Fields...................................................................................................................... 10-17
INTERVAL YEAR TO MONTH: Example............................................................................... 10-18
INTERVAL DAY TO SECOND Data Type: Example.............................................................. 10-20
Lesson Agenda........................................................................................................................... 10-21
EXTRACT................................................................................................................................. 10-22
TZ_OFFSET.............................................................................................................................. 10-23
FROM_TZ................................................................................................................................. 10-25
TO_TIMESTAMP..................................................................................................................... 10-26
TO_YMINTERVAL................................................................................................................... 10-27
TO_DSINTERVAL.................................................................................................................... 10-28
Daylight Saving Time (DST)..................................................................................................... 10-29
Quiz............................................................................................................................................ 10-31
Summary.................................................................................................................................... 10-32
Practice 10: Overview................................................................................................................ 10-33

xix

You might also like