Oracle Database 12c: SQL Workshop I: Chapter 1: Introduction
Oracle Database 12c: SQL Workshop I: Chapter 1: Introduction
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
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
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
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
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
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
xvi
Correlated DELETE.................................................................................................................. 7-15
Using Correlated DELETE........................................................................................................ 7-16
Summary.................................................................................................................................... 7-17
Practice 7: Overview.................................................................................................................. 7-18
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