cover next page > title : author : publisher : isbn10 | asin : print isbn13 : ebook isbn13 : language : subject publication date : lcc : ddc : subject : cover next page > < previous page page_iii next page > Page iii Oracle SQL*Plus The Definitive Guide Jonathan Gennick Beijing Cambridge Famham Köln Paris Sebastopol Taipei Tokyo < previous page page_iii next page > < previous page page_iv next page > Page iv Oracle SQL*Plus: The Definitive Guide by Jonathan Gennick Copyright © 1999 O'Reilly & Associates, Inc. All rights reserved. Printed in the United States of America. Published by O'Reilly & Associates, Inc. 101 Morris Street, Sebastopol, CA 95472. Editor: Deborah Russell Production Editor: Ellie Fountain Maden Printing History: March 1999: First Edition. ORACLE, Oracle, Oracle Enterprise Manager, Oracle Personal Edition, Oracle Procedure Builder, Oracle Server, Oracle Server Manager, Oracle Version 6, Oracle7, Oracle8, Oracle 8i, Net8, SQL*Loader, SQL*Net, and SQL*Plus are trademarks of Oracle Corporation. PowerBuilder is a trademark of PowerSoft. SQL Station is a trademark of Platinum Technology. Clear Access is a trademark of Sterling Software. Microsoft and Windows NT are registered trademarks of Microsoft Corporation. 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 the trademark claim, the designations have been printed in caps or initial caps. Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc. The use of the moving leaf image in association with Oracle SQL*Plus is a trademark of O'Reilly & Associates, Inc. While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 1-56592-578-5 [2/00] [M] < previous page page_iv next page > < previous page page_v next page > Page v I dedicate this book to my wife Donna, who, in spite of all my crazy dreams and ambitions, continues to stand with me. Jonathan Gennick < previous page page_v next page > < previous page page_vii next page > Page vii Table of Contents Preface xi 1. Introduction to SQL*Plus 1 What Is SQL*Plus 1 History of SQL*Plus 6 Why Master SQL*Plus 8 Creating and Loading the Sample Tables 9 2. Interacting with SQL*Plus 18 Starting SQL*Plus 18 Some Basic SQL*Plus Commands 26 Running SQL Queries 33 Working with PL/SQL 35 The SQL Buffer 40 Line Editing 40 Executing the Statement in the Buffer 51 Saving and Retrieving the Buffer 54 The Edit Command 57 Executing a Script 61 The Working Directory 62 3. Generating Reports with SQL*Plus 65 Following a Methodology 65 Saving Your Work 66 Designing a Simple Report 66 Advanced Report Formatting 86 < previous page page_vii next page > < previous page page_viii next page > Page viii Totals and Subtotals 97 Other Reporting Topics 106 4. Writing SQL*Plus Scripts 122 Why Write Scripts? 122 Using Substitution Variables 123 Prompting for Values 132 Cleaning Up the Display 137 Packaging Your Script 139 The DEFINE and UNDEFINE Commands 144 Controlling Variable Substitution 146 Commenting Your Scripts 151 5. Extracting and Loading Data 155 Types of Output Files 156 Limitations of SQL*Plus 157 Extracting the Data 158 Reloading the Data 167 6. Exploring Your Database 175 The DESCRIBE Command 175 Oracle's Data Dictionary Views 180 Tables 193 Table Constraints 200 Indexes 207 Triggers 214 Synonyms 218 Table Security 222 Finding More Information 225 7. Advanced Scripting 227 Bind Variables 228 Branching in SQL*Plus 243 Looping in SQL*Plus 254 Validating and Parsing User Input 262 Error Handling 270 8. Tuning and Timing 277 Using SQL*Plus Timers 277 Using EXPLAIN PLAN 283 < previous page page_viii next page > < previous page page_ix next page > Page ix Using AUTOTRACE 292 Improving on EXPLAIN PLAN Results 297 Where to Find More Tuning Information 308 9. The Product User Profile 309 What Is the Product User Profile? 309 Using the Product User Profile 316 10. Administration with SQL*Plus 326 Connecting for Administrative Purposes 326 Starting and Stopping a Database 330 Looking at Your Database 337 Database Backup and Recovery 340 11. Customizing Your SQL*Plus Environment 357 SQL*Plus Settings You Can Control 357 The Site and User Profiles 358 Environment Variable Settings 360 The SET Command 367 The SHOW Command 418 A. SQL*Plus Command Reference 423 B. SQL*Plus Format Elements 470 Index 479 < previous page page_ix next page > . First Edition. ORACLE, Oracle, Oracle Enterprise Manager, Oracle Personal Edition, Oracle Procedure Builder, Oracle Server, Oracle Server Manager, Oracle Version 6, Oracle7 , Oracle8 , Oracle 8i,. Introduction to SQL*Plus 1 What Is SQL*Plus 1 History of SQL*Plus 6 Why Master SQL*Plus 8 Creating and Loading the Sample Tables 9 2. Interacting with SQL*Plus 18 Starting SQL*Plus 18 Some Basic SQL*Plus. Queries 33 Working with PL/SQL 35 The SQL Buffer 40 Line Editing 40 Executing the Statement in the Buffer 51 Saving and Retrieving the Buffer 54 The Edit Command 57 Executing a Script 61 The Working Directory 62 3.