1. Trang chủ
  2. » Công Nghệ Thông Tin

OReilly mastering oracle SQL apr 2002 ISBN 0596001290

741 104 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Mastering Oracle SQL

  • Table of Contents

  • Copyright

  • Dedication

  • Preface

    • Why We Wrote This Book

    • Objectives of This Book

    • Audience for This Book

    • Platform and Version

    • Structure of This Book

    • Conventions Used in This Book

    • Comments and Questions

    • Acknowledgments

  • Chapter 1. Introduction to SQL

    • Section 1.1. What Is SQL?

    • Section 1.2. A Brief History of SQL

    • Section 1.3. A Simple Database

    • Section 1.4. DML Statements

  • Chapter 2. The WHERE Clause

    • Section 2.1. Life Without WHERE

    • Section 2.2. WHERE to the Rescue

    • Section 2.3. WHERE Clause Evaluation

    • Section 2.4. Conditions and Expressions

    • Section 2.5. WHERE to Go from Here

  • Chapter 3. Joins

    • Section 3.1. Inner Joins

    • Section 3.2. Outer Joins

    • Section 3.3. Self Joins

    • Section 3.4. Joins and Subqueries

    • Section 3.5. DML Statements on a Join View

    • Section 3.6 ANSI-Standard Join Syntax in Oracle9

  • Chapter 4. Group Operations

    • Section 4.1. Aggregate Functions

    • Section 4.2. The GROUP BY Clause

    • Section 4.3. The HAVING Clause

  • Chapter 5. Subqueries

    • Section 5.1. What Is a Subquery?

    • Section 5.2. Noncorrelated Subqueries

    • Section 5.3. Correlated Subqueries

    • Section 5.4. Inline Views

    • Section 5.5. Subquery Case Study: The Top N Performers

  • Chapter 6. Handling Temporal Data

    • Section 6.1. Internal DATE Storage Format

    • Section 6.2. Getting Dates In and Out of a Database

    • Section 6.3. Date Manipulation

    • Section 6.4 Oracle9

    • Section 6.5. INTERVAL Literals

  • Chapter 7. Set Operations

    • Section 7.1. Set Operators

    • Section 7.2. Using Set Operations to Compare Two Tables

    • Section 7.3. Using NULLs in Compound Queries

    • Section 7.4. Rules and Restrictions on Set Operations

  • Chapter 8. Hierarchical Queries

    • Section 8.1. Representing Hierarchical Information

    • Section 8.2. Simple Hierarchy Operations

    • Section 8.3. Oracle SQL Extensions

    • Section 8.4. Complex Hierarchy Operations

    • Section 8.5. Restrictions on Hierarchical Queries

  • Chapter 9. DECODE and CASE

    • Section 9.1. DECODE, NVL, and NVL2

    • Section 9.2. The Case for CASE

    • Section 9.3. DECODE and CASE Examples

  • Chapter 10. Partitions, Objects, and Collections

    • Section 10.1. Table Partitioning

    • Section 10.2. Objects and Collections

  • Chapter 11. PL/SQL

    • Section 11.1. What Is PL/SQL?

    • Section 11.2. Procedures, Functions, and Packages

    • Section 11.3. Calling Stored Functions from Queries

    • Section 11.4. Restrictions on Calling PL/SQL from SQL

    • Section 11.5. Stored Functions in DML Statements

    • Section 11.6. The SQL Inside Your PL/SQL

  • Chapter 12. Advanced Group Operations

    • Section 12.1. ROLLUP

    • Section 12.2. CUBE

    • Section 12.3. The GROUPING Function

    • Section 12.4. GROUPING SETS

    • Section 12.5 Oracle9

    • Section 12.6. The GROUPING_ID and GROUP_ID Functions

  • Chapter 13. Advanced Analytic SQL

    • Section 13.1. Analytic SQL Overview

    • Section 13.2. Ranking Functions

    • Section 13.3. Windowing Functions

    • Section 13.4. Reporting Functions

    • Section 13.5. Summary

  • Chapter 14. SQL Best Practices

    • Section 14.1. Know When to Use Specific Constructs

    • Section 14.2. Avoid Unnecessary Parsing

    • Section 14.3. Consider Literal SQL for Decision Support Systems

  • Colophon

  • Index

    • SYMBOL

    • Index A

    • Index B

    • Index C

    • Index D

    • Index E

    • Index F

    • Index G

    • Index H

    • Index I

    • Index J

    • Index K

    • Index L

    • Index M

    • Index N

    • Index O

    • Index P

    • Index R

    • Index S

    • Index T

    • Index U

    • Index V

    • Index W

    • Index Y

Nội dung

Table of • Contents • Index • Reviews • Examples Reader • Reviews • Errata Mastering Oracle SQL By Alan Beaulieu, Sanjay Mishra Publisher : O'Reilly Pub Date : April 2002 ISBN : 0-596-00129-0 Pages : 336 Slots : 1 Few books on the market today go beyond discussing syntax and the barest rudiments of using Oracle SQL This book changes that The authors cover the full range of Oracle SQL features that apply to query writing Learn to write UNION queries that take full advantage of SQL's set orientation, and ways to use Oracle's new analytic SQL features to write ranking queries, lag and lead queries, and more Table of • Contents • Index • Reviews • Examples Reader • Reviews • Errata Copyright Dedication Preface Mastering Oracle SQL By Alan Beaulieu, Sanjay Mishra Publisher : O'Reilly Pub Date : April 2002 ISBN : 0-596-00129-0 Pages : 336 Slots : 1 Why We Wrote This Book Objectives of This Book Audience for This Book Platform and Version Structure of This Book Conventions Used in This Book Comments and Questions Acknowledgments Chapter 1 Introduction to SQL Section 1.1 What Is SQL? Section 1.2 A Brief History of SQL Section 1.3 A Simple Database Section 1.4 DML Statements Chapter 2 The WHERE Clause Section 2.1 Life Without WHERE Section 2.2 WHERE to the Rescue Section 2.3 WHERE Clause Evaluation Section 2.4 Conditions and Expressions Section 2.5 WHERE to Go from Here Chapter 3 Joins Section 3.1 Inner Joins Section 3.2 Outer Joins Section 3.3 Self Joins Section 3.4 Joins and Subqueries Section 3.5 DML Statements on a Join View Section 3.6 ANSI-Standard Join Syntax in Oracle9i Chapter 4 Group Operations Section 4.1 Aggregate Functions Section 4.2 The GROUP BY Clause Section 4.3 The HAVING Clause Chapter 5 Subqueries Section 5.1 What Is a Subquery? Section 5.2 Noncorrelated Subqueries Section 5.3 Correlated Subqueries Section 5.4 Inline Views Section 5.5 Subquery Case Study: The Top N Performers Chapter 6 Handling Temporal Data Section 6.1 Internal DATE Storage Format Section 6.2 Getting Dates In and Out of a Database Section 6.3 Date Manipulation Section 6.4 Oracle9i New DATETIME Features Section 6.5 INTERVAL Literals Chapter 7 Set Operations Section 7.1 Set Operators Section 7.2 Using Set Operations to Compare Two Tables Section 7.3 Using NULLs in Compound Queries Section 7.4 Rules and Restrictions on Set Operations Chapter 8 Hierarchical Queries Section 8.1 Representing Hierarchical Information Section 8.2 Simple Hierarchy Operations Section 8.3 Oracle SQL Extensions Section 8.4 Complex Hierarchy Operations Section 8.5 Restrictions on Hierarchical Queries Chapter 9 DECODE and CASE Section 9.1 DECODE, NVL, and NVL2 Section 9.2 The Case for CASE Section 9.3 DECODE and CASE Examples Chapter 10 Partitions, Objects, and Collections Section 10.1 Table Partitioning Section 10.2 Objects and Collections Chapter 11 PL/SQL Section 11.1 What Is PL/SQL? Section 11.2 Procedures, Functions, and Packages Section 11.3 Calling Stored Functions from Queries Section 11.4 Restrictions on Calling PL/SQL from SQL Section 11.5 Stored Functions in DML Statements Section 11.6 The SQL Inside Your PL/SQL Chapter 12 Advanced Group Operations Section 12.1 ROLLUP Section 12.2 CUBE Section 12.3 The GROUPING Function Section 12.4 GROUPING SETS Section 12.5 Oracle9i Grouping Features Section 12.6 The GROUPING_ID and GROUP_ID Functions Chapter 13 Advanced Analytic SQL Section 13.1 Analytic SQL Overview Section 13.2 Ranking Functions Section 13.3 Windowing Functions Section 13.4 Reporting Functions Section 13.5 Summary Chapter 14 SQL Best Practices Section 14.1 Know When to Use Specific Constructs Section 14.2 Avoid Unnecessary Parsing Section 14.3 Consider Literal SQL for Decision Support Systems Colophon Index Copyright © 2002 O'Reilly & Associates, Inc All rights reserved Printed in the United States of America Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O'Reilly & Associates books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://safari.oreilly.com) For more information contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O'Reilly & Associates, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps Oracle® and all Oracle-based trademarks and logos are trademarks or registered trademarks of Oracle Corporation, Inc., in the United Status and other countries The association between the image of a lantern fly and the topic of mastering Oracle SQL is a trademark of O'Reilly & Associates, Inc While every precaution has been taken in the preparation of this book, the publisher and the authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein Dedication I dedicate this book to my father I wish he were alive to see this book Sanjay Mishra To my daughters, Michelle and Nicole Alan Beaulieu Preface SQL, which stands for Structured Query Language, is the language for accessing a relational database SQL provides a set of statements for storing and retrieving data to and from a relational database It has gained steadily in popularity ever since the first relational database was unleashed upon the world Other languages have been put forth, but SQL is now accepted as the standard language for almost all relational database implementations, including Oracle SQL is different from other programming languages because it is nonprocedural Unlike programs in other languages, where you specify the sequence of steps to be performed, a SQL program (more appropriately called a SQL statement) only expresses the desired result The responsibility for determining how the data will be processed in order to generate the desired result is left to the database management system The nonprocedural nature of SQL makes it easier to access data in application programs If you are using an Oracle database, SQL is the interface you use to access the data stored in your database SQL allows you to create database structures such as tables (to store your data), views, and indexes SQL allows you to insert data into the database, and to retrieve that stored data in a desired format (for example, you might sort it) Finally, SQL allows you to modify, delete, and otherwise manipulate your stored data SQL is the key to everything you do with the database It's important to know how to get the most out of that interface Mastery over the SQL language is one of the most vital requirements of a database developer or database administrator Why We Wrote This Book Our motivation for writing this book stems from our own experiences learning how to use the Oracle database and Oracle's implementation of the SQL language Oracle's SQL documentation consists of a reference manual that doesn't go into details about the practical usefulness of the various SQL features that Oracle supports Nor does the manual present complex, real-life examples When we looked for help with SQL in the computer book market, we found that there are really two types of SQL books available Most are the reference type that describe features and syntax, but that don't tell you how to apply that knowledge to real-life problems The other type of book, very few in number, discusses the application of SQL in a dry and theoretical style without using any particular vendor's implementation Since every database vendor implements their own variation of SQL, we find books based on "standard" SQL to be of limited usefulness In writing this book, we decided to write a practical book focused squarely on Oracle's version of SQL Oracle is the market-leading database, and it's also the database on which we've honed our SQL expertise In this book, we not only cover the most important and useful of Oracle's SQL features, but we show ways to apply them to solve specific problems Objectives of This Book The single most important objective of this book is to help you harness the power of Oracle SQL to the maximum extent possible You will learn to: Understand the features and capabilities of the SQL language, as implemented by Oracle Use complex SQL features such as outer joins, correlated subqueries, hierarchical queries, grouping operations, analytical queries, etc Use DECODE and CASE to implement conditional logic in your SQL queries Write SQL statements that operate against partitions, objects, and collections such as nested tables and variable arrays Use the new SQL features introduced in Oracle9i, such as new date and time features, ANSI-compliant joins, and new grouping and analytical functions Use best practices to write efficient, maintainable SQL queries Audience for This Book This book is for Oracle developers and database administrators Whether you are new to the world of databases or a seasoned professional, if you use SQL to access an Oracle database, this book is for you Whether you use simple queries to access data or embed them in PL/SQL or Java programs, SQL is the core of all data access tasks in your application Knowing the power and flexibility of SQL will improve your productivity, allowing you to get more done in less time, and with increased certainty that the SQL statements you write are indeed correct [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [Y] range conditions range partitions ranges dates, returning eliminating gaps RANK analytic function RANK function ranking analytic functions DENSE_RANK overview RANK ROW_NUMBER RATIO_TO_REPORT analytic function records, listing in hierarchical order recursive relationships, traversing relationships collection types creating nested tables unnesting variable arrays correlated subqueries hierarchical data representations key-preserved tables recursive, traversing self-referential integrity constraints reporting analytic functions RATIO_TO_REPORT report partitions RESTRICT_REFERENCES pragma result sets Cartesian products 2nd finding what data is not in database refining, WHERE clause set operations, column names subqueries transforming CASE expression DECODE function WHERE clause, conditions retrieving data customer table SELECT statement RIGHT keyword, ANSI join syntax ROLLUP keyword group operations partial rollups root nodes finding finding parents listing root, hierarchical queries ROUND function rounding, dates ROW_NUMBER analytic function ROWID ROWNUM, GROUP BY clause and ROWS BETWEEN clause, unbounded windows RR (year) indicator RRRR (year) indicator RTRIM function, dates [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [Y] sample database, overview scalar subqueries scripts, PL/SQL searched CASE expressions seconds, fractional overview TIMESTAMP datatype TIMESTAMP WITH LOCAL TIME ZONE datatype TIMESTAMP WITH TIME ZONE datatype SELECT statement analytic functions clause references correlated subqueries dates, ranges DISTINCT keyword DML (Data Manipulation Language) inline views aggregate queries, overcoming limitations of creating data sets execution hierarchical queries, overcoming limitations of overview joins, subqueries noncorrelated subqueries multiple-column multiple-row overview scalar object types ORDER BY clause stored functions, calling from subqueries UNION queries WHERE clause self joins 2nd non-equi outer SELF keyword, object types self-referential integrity constraints semi-joins session time zones SESSIONTIMEZONE function SET clause, multiple-column subqueries set operations INTERSECT operator 2nd MINUS operator 2nd comparing tables restrictions tables, comparing UNION ALL operator 2nd comparing tables UNION operator 2nd SET TIME_ZONE clause simple CASE expressions sorting, ORDER BY clause specifying format SQL (Structured Query Language) history Oracle and ANSI compliance overview queries compared to DSS queries standards, ANSI START WITH clause hierarchical queries START WITH CONNECT BY clause, hierarchical queries state, controlling CASE expression DECODE function statements CREATE TABLE, object tables CREATE TYPE BODY DELETE join views multiple-column subqueries scalar subqueries DML join views and INSERT converting strings to date format join views specifying partitions SELECT clause references correlated subqueries DISTINCT keyword inline views 2nd 3rd 4th 5th 6th noncorrelated subqueries 2nd 3rd 4th object types ORDER BY clause returning between date ranges subqueries UNION operations WHERE clause stored functions and UPDATE CASE expression DECODE function inline views join views multiple-column subqueries optional updates selective aggregation storage, partitions and stored functions calling restrictions consistency issues DML statements joins, avoiding packages rules TRUST keyword views stored procedures compared to stored functions packages strings converting to dates 2nd creating from dates pattern-matching Structured Query Language [See SQL] style, coding SUBPARTITION clause subpartitions deleting subqueries 2nd case study comparison operators and correlated inline views aggregate queries, overcoming limitations of creating data sets execution hierarchical queries, overcoming limitations of overview joins noncorrelated multiple-column multiple-row overview scalar outer joins subtotals, generating subtraction (-) operator, dates subtraction, dates subtrees, deleting summaries [See also group operations] date math GROUP BY clause SYSTIMESTAMP function [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [Y] table aliases new join syntax and SELECT statements self joins when to use TABLE expression, querying collections tables ANSI join syntax advantages outer joins comparing, set operations customer, SELECT statement example entities equi-joins compared to non-equi-joins inner joins joins, subqueries key-preserved, join views and modifying UPDATE statement without WHERE clause NOT NULL columns, INSERT statement and object type outer joins 2nd full restrictions partitioning, overview self joins non-equi outer self-referential integrity constraints terminology hierarchical queries text, date formatting, case sensitivity rules time AM/PM indicators fractional seconds overview TIMESTAMP datatype TIMESTAMP WITH LOCAL TIME ZONE datatype TIMESTAMP WITH TIME ZONE datatype functions rounding and truncating dates time zones database default NEW_TIME function overview session TIMESTAMP datatype TIMESTAMP WITH LOCAL TIME ZONE datatype TIMESTAMP WITH TIME ZONE datatype TO_CHAR function combining with TO_DATE function overview TO_DATE function combining with TO_CHAR function default date format overview specifying format TO_DSINTERVAL function TO_TIMESTAMP function TO_TIMESTAMP_TZ function TO_YMINTERVAL function top-n/bottom-n queries (analytic ranking functions) traversing hierarchical trees TRUNC function date pivot tables date ranges and truncating dates TRUST keyword, stored procedures two-digit years TZ_OFFSET function [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [Y] underscore (_), pattern-matching character UNION ALL set operator 2nd comparing tables UNION clause, data sets, creating custom union compatibility conditions UNION operation compared to UNION ALL UNION queries ANSI join syntax and full outer joins UNION set operator 2nd UPDATE statement CASE expression collections and DECODE function DML (Data Manipulation Language) inline views join views multiple-column subqueries optional updates selective aggregation WHERE clause and USER_UPDATABLE_COLUMNS data dictionary view USING clause UTC (Coordinated Universal Time) [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [Y] VALUE function, returning objects VARCHAR2 datatype, TO_DATE datatype variable arrays variables, blind varrays vertical joins vertical partitioning viewing all in schema views data dictionary, USER_UPDATABLE_COLUMNS hierarchical queries inline aggregate queries, overcoming limitations of creating data sets DML statements execution hiding columns with WITH CHECK OPTION hierarchical queries, overcoming limitations of overview selective aggregation joins, DML statements and outer joins partitions stored functions [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [Y] weekends, date math and weeks date math ISO standard WHERE clause capabilities of columns, restricting access compared to HAVING clause conditions components of equality/inequality matching membership range evaluation conditions GROUP BY clause HAVING clause and hierarchical queries, filtering join conditions 2nd logical operators new join syntax and noncorrelated subqueries NULL expression outer join operator (+) partition pruning subqueries tips for using UPDATE statement and value of WHERE clause (SELECT statements) WIDTH_BUCKET analytic function windowing analytic functions WITH CHECK OPTION clause WITH CHECK OPTION, hiding columns working days, calculating WW (ISO week) indicator [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [R] [S] [T] [U] [V] [W] [Y] years AD/BC indicators finding number between dates ISO standard two-digit YY (year) indicator ... Reviews • Errata Copyright Dedication Preface Mastering Oracle SQL By Alan Beaulieu, Sanjay Mishra Publisher : O'Reilly Pub Date : April 2002 ISBN : 0-596-00129-0 Pages : 336 Slots : 1 Why We Wrote This Book... Chapter 11 explores the integration of SQL and PL /SQL This chapter describes how to call PL /SQL stored procedures and functions from SQL statements, and how to write efficient SQL statements within PL /SQL programs Chapter 12 deals with complex grouping operations used mostly in... The single most important objective of this book is to help you harness the power of Oracle SQL to the maximum extent possible You will learn to: Understand the features and capabilities of the SQL language, as implemented by Oracle Use complex SQL features such as outer joins, correlated

Ngày đăng: 26/03/2019, 17:12