Академический Документы
Профессиональный Документы
Культура Документы
Student Guide
40060GC10
Production 1.0
November 2001
D34060
Author Copyright © Oracle Corporation, 2001. All rights reserved.
Shane Mattimoe All other products or company names are used for identification purposes only, and
may be trademarks of their respective owners.
Contents
Preface
Introduction
Objectives I-2
System Development Life Cycle I-3
Data Storage on Different Media I-5
Relational Database Concepts I-6
Data Models I-7
The Employee and Department Data Model I-9
Definition of a Relational Database I-10
The EMPLOYEES Table I-11
Relational Database Terminology I-12
Relating Multiple Tables I-14
Oracle8: Object Relational Database Management System I-16
Oracle8i: Internet Platform I-17
Oracle9i I-18
Oracle9i Application Server I-20
Oracle9i Database I-21
Communicating with RDBMS Using SQL I-22
Data Types Supported in SQL I-24
SQL Statements I-26
Overview of Course Material I-28
Tables Used in the Course I-29
Summary I-30
1 Writing Basic SELECT SQL Statements
Objectives 1-2
Capabilities of SQL SELECT Statements 1-3
Basic SELECT Statement 1-4
Writing SQL Statements 1-6
Retrieving All Columns from a Table 1-7
Selecting All Columns 1-8
Creating a Projection on a Table 1-9
Selecting Specific Columns 1-10
Default Data Justification 1-12
Arithmetic Expressions 1-13
Using Arithmetic Operators 1-14
Using Arithmetic Operators on Multiple Columns 1-15
Operator Precedence 1-16
Using Parentheses 1-18
Defining a Column Alias 1-19
Using Column Aliases 1-20
The Concatenation Operator 1-21
Using the Concatenation Operator 1-22
Literals 1-23
Using Literal Character Strings 1-24
Duplicate Rows 1-25
iii
Eliminating Duplicate Rows 1-26
SQL and iSQL*Plus Interaction 1-27
SQL Statements Versus iSQL*Plus Commands 1-28
Overview of iSQL*Plus 1-29
Logging On to iSQL*Plus 1-30
The iSQL*Plus Environment 1-32
Interactig with Script Files 1-33
Displaying Table Structure 1-37
Summary 1-39
Practice 1 Overview 1-40
2 Restricting and Sorting Data
Objectives 2-2
Limiting Rows by Using a Restriction 2-3
Limiting the Rows Selected by a Query 2-4
Using the WHERE Clause 2-5
Character Strings and Dates 2-6
Comparison Operators 2-7
Using the Comparison Operators with Characters 2-8
Other SQL Comparison Operators 2-9
Using the BETWEEN Operator 2-10
Using the IN Operator 2-11
Using the IN Operator with Strings 2-12
Using the LIKE Operator 2-13
Using the IS NULL Operator 2-15
Logical Operators 2-16
Using the AND Operator 2-17
Using the OR Operator 2-19
Using the NOT Operator 2-21
Rules of Precedence 2-25
ORDER BY Clause 2-28
Sorting in Descending Order 2-29
Sorting by Column Alias 2-30
Sorting by Multiple Columns 2-31
Sorting by a Column Not in the SELECT List 2-32
Summary 2-33
Practice 2 Overview 2-34
3 Single-Row Number and Character Functions
Objectives 3-2
How does a Function Work? 3-3
How SQL Functions Work 3-4
Example of a Function 3-5
Two Types of SQL Functions 3-6
Single-Row Functions 3-7
Calling a Function in SQL 3-9
iv
Character Functions 3-10
Case Conversion Functions 3-11
Using Case Conversion Functions 3-12
Number Functions 3-14
Using the ROUND Function 3-15
Using the TRUNC Function 3-16
Defining a NULL Value 3-17
Null Values in Arithmetic Expressions 3-18
The NVL Function 3-19
Using the NVL Function to Handle Null Values 3-20
Summary 3-21
Practice 3 Overview 3-22
4 Single-Row Date and Conversion Functions
Objectives 4-2
Single-Row Functions 4-3
Working with Dates 4-4
RR Date Format 4-6
SYSDATE 4-7
Arithmetic with Dates 4-8
Using Arithmetic Operators with Dates 4-9
Using SYSDATE in Calculations 4-10
Explicit Data Type Conversion 4-11
Modifying the Display Format of Dates 4-13
TO_CHAR Function with Dates 4-14
Date Format Model Elements 4-15
Using the TO_CHAR Function with Dates 4-17
Date Format Model Elements 4-24
Using Format Models to Display Time 4-26
TO_CHAR Function with Numbers 4-28
Using the TO_CHAR Function with Numbers 4-30
Using the TO_NUMBER and TO_DATE Functions 4-31
Using the TO_NUMBER Function 4-32
Using the TO_DATE Function 4-33
Date Functions 4-34
Using Date Functions 4-35
Examples of Date Functions 4-36
Nesting Functions 4-37
Using ROUND and TRUNC with Date Functions 4-40
Summary 4-41
Practice 4 Overview 4-42
5 Displaying Data from Multiple Tables
Objectives 5-2
Obtaining Data From Multiple Tables 5-3
Joining Tables Using Oracle Syntax 5-4
Cartesian Product 5-6
v
Generating a Cartesian Product 5-7
Types of Joins 5-9
What Is an Equijoin? 5-10
Retrieving Records with Equijoins 5-11
Qualifying Ambiguous Column Names 5-12
Additional Search Conditions Using the AND Operator 5-13
Using Additional Search Conditions with a Join 5-14
Table Aliases 5-16
Using Table Aliases 5-17
Joining More than Two Tables 5-18
Non-Equijoins 5-19
Retrieving Records with Nonequijoins 5-20
Using Multiple Joins 5-21
Self Joins 5-22
Joining a Table to Itself 5-23
Joining Tables Using SQL: 1999 Syntax 5-24
Creating Cross Joins 5-25
Creating Natural Joins 5-26
Retrieving Records with Natural Joins 5-27
Summary 5-28
Practice 5 Overview 5-29
vi
Using a Subquery 7-5
Guidelines for Using Subqueries 7-6
Types of Subqueries 7-7
Single-Row Subqueries 7-8
Executing Single-Row Subqueries 7-9
Using Group Functions in a Subquery 7-12
Will This Statement Work? 7-13
What is Wrong with This Statement? 7-14
Multiple-Row Subqueries 7-15
Using Group Functions in a Multiple-Row Subquery 7-16
Summary 7-18
Practice 7 Overview 7-19
8 iSQL*Plus
Objectives 8-2
Interactive Reports 8-3
Substitution Variables 8-4
Using the & Substitution Variable 8-5
Using the SET VERIFY Command 8-6
Character and Date Values with Substitution Variables 8-8
Specifying Column Names, Expressions, and Text at Run Time 8-10
Specifying Column Names at Run Time 8-11
Specifying Column Names and Expressions at Run Time 8-13
Specifying Column Names, Expressions, and Text at Run Time 8-14
Using the && Substitution Variable 8-15
Defining User Variables 8-17
DEFINE and UNDEFINE Commands 8-18
Using the DEFINE Command 8-19
Customing the iSQL*PLUS Environment 8-20
SET Command Variables 8-21
Using SET Command Variables 8-22
iSQL*Plus Format Commands 8-24
The COLUMN Command 8-25
Using the COLUMN Command 8-26
COLUMN Format Models 8-29
Using the BREAK Command 8-30
Creating a Script File to Run a Report 8-32
Sample Report 8-34
Summary 8-35
Practice 8 Overview 8-36
Appendix A: Manipulating Data
Appendix B: Reporting with SQL*Plus
vii
Appendix C: Practice Solutions
viii