Anda di halaman 1dari 8

Oracle Database 11g: Introduction for Experienced SQL Users

Student Guide

D53977GC10 Edition 1.0 June 2008 D55263

Author
Tulika Srivastava

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

Technical Contributors and Reviewers


Maria Billings Thomas Chang Laurent Dereac Lex Van Der Werff Bjorn Engsig Gerlinde Frenzen Nancy Greenberg Trevor Haley Yash Jain Angelika Krupp Diana Lorentz Ramaa Mani Nagavalli Pataballa Srinivas Putrevu Aniket Raut Bryan Roberts Helen Robertson Lata Shivaprasad Grant Spencer James Spiller Janet Stern Tone Thomas Jaco Verheul John Walsh

Editors
Vijayalakshmi Narasimhan Raj Kumar

Graphic Designer
Satish Bettegowda

Publishers
Sujatha Nagendra Nita Brozowski

Contents

Course Introduction Objectives I-2 Course Agenda I-3 Human Resources (HR) Schema I-5 Understanding the Oracle Database Environment Objectives 1-2 Understanding the Oracle Database Environment 1-3 Getting to Know the Oracle Database 1-4 Demystifying Grid Computing 1-6 Exploring the Database Architectural Components 1-7 Exploring the Architectural Components 1-9 Understanding the Oracle Instance 1-11 Connecting to an Instance 1-13 Processing a SQL Statement 1-15 Understanding Data Flow During SQL Statement Processing 1-18 Understanding Read Consistency 1-20 Summary 1-23 Practice 1: Overview 1-24 Using SQL Developer Objectives 2-2 What Is Oracle SQL Developer? 2-3 Specifications of SQL Developer 2-4 SQL Developer Interface 2-5 Creating a Database Connection 2-7 Browsing Database Objects 2-10 Creating a Schema Object 2-11 Creating a New Table: Example 2-12 Using the SQL Worksheet 2-13 Executing SQL Statements 2-16 Formatting the SQL Code 2-17 Saving SQL Statements 2-18 Running Script Files 2-19

iii

Using Snippets 2-20 Using Snippets: Example 2-21 Using SQL*Plus 2-22 Debugging Procedures and Functions 2-23 Database Reporting 2-24 Creating a User-Defined Report 2-25 Search Engines and External Tools 2-26 Setting Preferences 2-27 Summary 2-28 Practice 2: Overview 2-29 3 Getting Started with Oracle SQL Objectives 3-2 Retrieving Data by Using the SELECT Statement 3-3 Restricting Output by Using the WHERE Clause 3-5 Defining NULL 3-7 Using Pseudocolumns 3-8 Manipulating Data Items by Using Operators 3-11 Calculating Using Arithmetic Expressions 3-13 Manipulating Strings by Using the Concatenation Operator 3-14 Combining Results by Using Set Operators 3-15 Using the UNION Operator 3-16 Using Expressions 3-18 Conditional Querying Using the CASE Expression 3-19 Using Conditions 3-21 Understanding Functions 3-22 SQL Functions: Types 3-23 Manipulating Data Items Using Single-Row Functions 3-24 Using Numeric Functions 3-26 Using the ROUND and TRUNC Functions 3-27 Practice 3: Overview of Part 1 3-29 Understanding Data Types 3-30 Using Datetime Data Types 3-33 Date Functions 3-35 Using Datetime Data Types 3-36 Using INTERVAL Data Types 3-38 Converting Between Data Types 3-41 Converting Data Types Explicitly 3-43 Displaying a Date in a Specific Format 3-44 Date Format Model Elements 3-45

iv

Date Format Model Elements: Time Formats 3-46 Using the TO_CHAR Function with Dates and Numbers 3-47 Using the TO_NUMBER and TO_DATE Functions 3-49 Summary 3-50 Practice 3: Overview of Part 2 3-51 4 Combining Tables by Using Advanced Queries Objectives 4-2 Understanding Subqueries 4-3 Using a Subquery 4-5 Using Multiple-Column Subqueries 4-6 Comparing Columns 4-7 Comparing Using Pairwise Comparison Subquery 4-8 Comparing Using Nonpairwise Comparison Subqueries 4-9 Row-By-Row Processing Using Correlated Subqueries 4-11 Updating Rows Using Correlated UPDATE Operations 4-14 Deleting Rows Using Correlated DELETE Operations 4-16 Using a Subquery in the FROM Clause 4-17 Top-N Analysis 4-18 Top-N Analysis: Example 4-20 Joining Tables Using Oracle Syntax 4-21 Retrieving Records with Equijoins 4-22 Qualifying Ambiguous Column Names 4-23 Understanding Nonequijoins 4-25 Using Outer Joins to Return Records with No Direct Matches 4-27 Joining a Table to Itself 4-29 Comparing ANSI SQL Join Syntax with Oracle SQL Join Syntax 4-30 Using the Subquery Factoring Clause 4-31 Subquery Factoring Clause: Example 4-32 Subquery Factoring Clause: Example 4-33 Retrieving Data Hierarchically 4-34 Sample Data from the EMPLOYEES Table 4-35 Natural Tree Structure 4-36 Hierarchical Queries 4-37 Walking the Tree 4-39 Walking the Tree: From the Bottom Up 4-41 Walking the Tree: From the Top Down 4-42 Ranking Rows with the LEVEL Pseudocolumn 4-43 Formatting Hierarchical Reports Using LEVEL and LPAD 4-45 Pruning Branches 4-47

Summary 4-48 Practice 4: Overview 4-49 5 Creating and Managing Tables Objectives 5-2 Displaying the Table Structure 5-3 The CREATE TABLE Statement 5-5 Creating a Table Using a Subquery 5-8 Altering the Table Structure 5-10 Adding a Column 5-11 Modifying and Dropping Columns 5-12 Marking a Column as Unused 5-14 Guaranteeing Data Integrity 5-16 Understanding Constraints 5-18 Defining Constraints 5-19 Guidelines for Defining Constraints 5-22 Adding a Constraint 5-24 Disabling and Enabling Constraints 5-25 Dropping a Constraint 5-28 Cascading Constraints 5-29 Deferring Constraint Checking 5-31 Changing the Enforcement of Constraints 5-32 Enforcing Primary and Unique Key Constraints 5-33 Maintaining Tables in a Foreign Key Relationship 5-34 Renaming a Table 5-36 Truncating a Table 5-37 Dropping a Table 5-38 Adding Comments to a Table 5-39 Understanding the Types of Tables in the Oracle Database 5-40 Querying the Data Dictionary 5-42 Viewing Constraints 5-43 Summary 5-45 Practice 5: Overview 5-47 Creating and Managing Other Oracle Database Objects Objectives 6-2 Understanding Database Objects 6-3 Understanding Indexes 6-4 Creating an Index 6-6 Confirming Indexes 6-9 Creating Function-Based Indexes 6-10
vi

Creating an Index While Creating a Table 6-12 Removing an Index 6-14 Understanding Views 6-15 Creating a View 6-16 Querying a View 6-19 Modifying a View 6-20 Performing DML Operations on a View 6-21 Differentiating Simple Views from Complex Views 6-22 Creating a Complex View 6-23 Using the WITH CHECK OPTION Clause 6-25 Denying DML Operations 6-26 Removing a View 6-27 Understanding Materialized Views 6-28 Creating a Materialized View 6-30 Understanding Sequences 6-31 Creating a Sequence 6-32 Confirming Sequences 6-34 Using a Sequence 6-35 Using a Sequence: Example 6-37 Caching Sequence Values 6-38 Altering a Sequence 6-40 Modifying Sequences: Guidelines 6-41 Removing a Sequence 6-42 Creating a Synonym for an Object 6-43 Creating and Removing Synonyms 6-44 Summary 6-45 Practice 6: Overview 6-47 7 Controlling User Access Objectives 7-2 Controlling User Access 7-3 Understanding System Privileges 7-4 Creating Users 7-5 Granting System Privileges to a User 7-6 Granting System Privileges 7-7 Understanding Roles 7-8 Creating a Role 7-9 Changing Your Password 7-10 Understanding Object Privileges 7-11 Granting Object Privileges 7-13 Using the WITH GRANT OPTION and PUBLIC Keywords 7-14
vii

Confirming Privileges Granted 7-16 Revoking Object Privileges 7-18 Understanding Database Links 7-19 Creating Database Links 7-21 Summary 7-23 Practice 7: Overview 7-24 8 Oracle Database Extensions to DML and DDL Statements Objectives 8-2 Using Multitable INSERT Statements 8-3 Using Unconditional INSERT ALL 8-8 Using Conditional INSERT ALL 8-9 Using Conditional FIRST INSERT 8-11 Using Pivoting INSERT 8-13 Merging Rows by Using the MERGE Statement 8-16 Understanding External Tables 8-19 Creating an External Table 8-20 Creating an External Table: Example 8-22 Querying External Tables 8-26 Understanding Database Transactions 8-27 Using the COMMIT and ROLLBACK Statements 8-29 Committing Changes 8-31 Rolling Back Changes 8-34 Understanding Statement-Level Rollbacks 8-35 Summary 8-36 Practice 8: Overview 8-37 Appendix A: Practices and Solutions Appendix B: Table Descriptions and Data Appendix C: Using SQL*Plus Appendix D: ANSI Joins Appendix E: Advanced Features of Oracle SQL Appendix F: Additional Practices Appendix G: Additional Practice Solutions

viii

Anda mungkin juga menyukai