® Oracle Database 11g : The Complete Reference This page intentionally left blank ® Oracle Database 11g : The Complete Reference Kevin Loney New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Copyright © 2009 by The McGraw-Hill Companies, Inc All rights reserved Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher ISBN: 978-0-07-159876-7 MHID: 0-07-159876-6 The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-159875-0, MHID: 0-07-159875-8 All trademarks are trademarks of their respective owners Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark Where such designations appear in this book, they have been printed with initial caps McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs To contact a representative please visit the Contact Us page at www.mhprofessional.com Information has been obtained by Publisher from sources believed to be reliable However, because of the possibility of human or mechanical error by our sources, Publisher, or others, Publisher does not guarantee to the accuracy, adequacy, or completeness of any information included in this work and is not responsible for any errors or omissions or the results obtained from the use of such information Oracle Corporation does not make any representations or warranties as to the accuracy, adequacy, or completeness of any information contained in this Work, and is not responsible for any errors or omissions TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc (“McGraw-Hill”) and its licensors reserve all rights in and to the work Use of this work is subject to these terms Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited Your right to use the work may be terminated if you fail to comply with these terms THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE McGraw-Hill and its licensors not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom McGraw-Hill has no responsibility for the content of any information accessed through the work Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise This book is dedicated to my family and friends You are a blessing indeed About the Author Kevin Loney is an internationally recognized expert in the design, development, administration, and tuning of Oracle databases An enterprise database architect in the financial industry, he was named Consultant of the Year by Oracle Magazine in 2002 His best-selling books include Oracle Database 11g DBA Handbook, Oracle Advanced Tuning and Administration, and Oracle SQL & PL/SQL Annotated Archives He is the author of numerous technical articles in industry magazines and presents at Oracle user conferences in North America and Europe, where he is regularly among the highest-rated presenters About the Contributors Scott Gossett (contributing author, technical editor) is a technical director in the Oracle Advanced Technologies Solutions organization with more than 20 years experience specializing in RAC, performance tuning, and high-availability databases Prior to becoming a technical director, Scott was a senior principal instructor for Oracle Education for over 12 years, primarily teaching Oracle internals, performance tuning, RAC, and database administration In addition, Scott is one of the architects and primary authors of the Oracle Certified Master exam Scott has been a technical editor for nine Oracle Press books Sreekanth Chintala (technical editor) is an OCP-certified DBA, has been using Oracle technologies for 10+ years, and has more than 15 years of IT experience Sreekanth specializes in Oracle high availability, disaster recovery, and grid computing Sreekanth is an author of many technical white papers and a frequent speaker at Oracle OpenWorld, IOUG, and local user group meetings Sreekanth is active in the Oracle community and is the current web seminar chair for the community-run Oracle Real Application Clusters Special Interest Group (www.ORACLERACSIG.org) Contents at a Glance PART I Critical Database Concepts Oracle Database 11g Architecture Options Installing Oracle Database 11g and Creating a Database 11 Upgrading to Oracle Database 11g 21 Planning Oracle Applications—Approaches, Risks, and Standards 31 PART II SQL and SQL*Plus The Basic Parts of Speech in SQL Basic SQL*Plus Reports and Commands Getting Text Information and Changing It Searching for Regular Expressions Playing the Numbers 65 91 113 139 155 10 Dates: Then, Now, and the Difference 175 11 Conversion and Transformation Functions 12 Grouping Things Together 13 When One Query Depends upon Another 14 Some Complex Possibilities 15 Changing Data: insert, update, merge, and delete 16 DECODE and CASE: if, then, and else in SQL 17 Creating and Managing Tables, Views, Indexes, Clusters, and Sequences 18 Partitioning 19 Basic Oracle Security 197 209 223 241 257 277 293 323 331 vii PART III Beyond the Basics 20 Advanced Security—Virtual Private Databases 21 Advanced Security: Transparent Data Encryption 22 Working with Tablespaces 23 Using SQL*Loader to Load Data 24 Using Data Pump Export and Import 25 Accessing Remote Data 26 Using Materialized Views 27 Using Oracle Text for Text Searches 28 Using External Tables 29 Using Flashback Queries 30 Flashback—Tables and Databases 31 SQL Replay 355 367 375 385 399 417 429 449 467 483 493 501 PART IV PL/SQL 32 An Introduction to PL/SQL 513 33 Online Application Upgrades 535 34 Triggers 549 35 Procedures, Functions, and Packages 36 Using Native Dynamic SQL and DBMS_SQL 37 PL/SQL Tuning 569 589 597 PART V Object-Relational Databases 38 Implementing Object Types, Object Views, and Methods 611 39 Collectors (Nested Tables and Varying Arrays) 625 40 Using Large Objects 639 41 Advanced Object-Oriented Concepts 665 PART VI Java in Oracle 42 An Introduction to Java 683 43 JDBC Programming 699 44 Java Stored Procedures 709 Contents at a Glance ix Hitchhiker’s Guides 45 The Hitchhiker’s Guide to the Oracle Data Dictionary 723 46 The Hitchhiker’s Guide to Tuning Applications and SQL 769 47 SQL Result Cache and Client-Side Query Cache 811 48 Case Studies in Tuning 823 49 Advanced Architecture Options—DB Vault, Content DB, and Records DB 50 Oracle Real Application Clusters 51 The Hitchhiker’s Guide to Database Administration 52 The Hitchhiker’s Guide to XML in Oracle 835 847 857 883 PART VIII Alphabetical Reference Index 899 1295 ...® Oracle Database 11g : The Complete Reference This page intentionally left blank ® Oracle Database 11g : The Complete Reference Kevin Loney New York Chicago... of Oracle databases An enterprise database architect in the financial industry, he was named Consultant of the Year by Oracle Magazine in 2002 His best-selling books include Oracle Database 11g. .. Group (www.ORACLERACSIG.org) Contents at a Glance PART I Critical Database Concepts Oracle Database 11g Architecture Options Installing Oracle Database 11g and Creating