ORACLE Color profile: Generic CMYK printer profile Composite Default screen Series TIGHT / Oracle9i: The Complete Reference / Loney, Koch / 222521-1 / Front Matter Blind Folio FM:i Oracle9i: The Complete Reference Kevin Loney George Koch And the Experts at TUSC McGraw-Hill/Osborne New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto P:\010Comp\Oracle8\521-1\CD\Ventura\book.vp Friday, July 19, 2002 4:10:30 PM ORACLE Color profile: Generic CMYK printer profile Composite Default screen Series TIGHT / Oracle9i: The Complete Reference / Loney, Koch / 222521-1 / Front Matter Blind Folio FM:ii McGraw-Hill/Osborne 2600 Tenth Street Berkeley, California 94710 U.S.A To arrange bulk purchase discounts for sales promotions, premiums, or fund-raisers, please contact McGraw-Hill/Osborne at the above address For information on translations or book distributors outside the U.S.A., please see the International Contact Information page immediately following the index of this book Oracle 9i: The Complete Reference Copyright © 2002 by The McGraw-Hill Companies, Inc (Publisher) All rights reserved Printed in the United States of America Except as permitted under the 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 Publisher Oracle is a registered trademark and Oracle9i is a trademark or registered trademark of Oracle Corporation 1234567890 DOC DOC 0198765432 Book p/n 0-07-222707-9 and CD p/n 0-07-222708-7 parts of ISBN 0-07-222521-1 Publisher Brandon A Nordin Copy Editor Margaret Berson Vice President & Associate Publisher Scott Rogers Proofreader Cheryl Abel Acquisitions Editor Lisa McClain Indexer James Minkin Project Editor LeeAnn Pickrell Computer Designers Tabitha M Cagan, Lucie Ericksen Acquisitions Coordinator Athena Honore Illustrators Michael Mueller, Lyssa Wald Technical Editor Bob Bryla Cover Series Design Damore Johann Design, Inc This book was composed with Corel VENTURA™ Publisher 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 P:\010Comp\Oracle8\521-1\CD\Ventura\book.vp Friday, July 19, 2002 4:10:31 PM ORACLE Color profile: Generic CMYK printer profile Composite Default screen Series TIGHT / Oracle9i: The Complete Reference / Loney, Koch / 222521-1 / Front Matter Blind Folio FM:iii To my parents, and to Sue, Emily, Rachel, and Jane —K.L To Elwood Brant, Jr (Woody), 1949–1990 —G.K P:\010Comp\Oracle8\521-1\CD\Ventura\book.vp Friday, July 19, 2002 4:10:31 PM ORACLE Color profile: Generic CMYK printer profile Composite Default screen Series TIGHT / Oracle9i: The Complete Reference / Loney, Koch / 222521-1 / Front Matter Blind Folio FM:iv About the Authors Kevin Loney is a senior management technical consultant with TUSC (http://www.tusc.com), an Oracle-focused consultancy headquartered in Chicago He is an expert in the administration, tuning, security, recovery, design, and development of Oracle databases and applications An Oracle DBA and developer since 1987, he is the primary author of numerous books, including Oracle9i DBA Handbook, Oracle9i Instant Scripts, and Oracle8 Advanced Tuning and Administration, all published by Oracle Press He is a frequent presenter at local and international Oracle user groups George Koch is a leading authority on relational database applications A popular speaker and widely published author, he is also the creator of THESIS, the securities trading, accounting, and portfolio management system that was the first major commercial applications product in the world to employ a relational database (Oracle) and provide English language querying to its users He is a former senior vice president of Oracle Corporation P:\010Comp\Oracle8\521-1\CD\Ventura\book.vp Friday, July 19, 2002 4:10:31 PM ORACLE Color profile: Generic CMYK printer profile Composite Default screen Series TIGHT / Oracle9i: The Complete Reference / Loney, Koch / 222521-1 / Chapter 55 Blind Folio 55:v Contents At a Glance PART I Critical Database Concepts Sharing Knowledge and Success The Dangers in a Relational Database 15 The Basic Parts of Speech in SQL 41 The Basics of Object-Relational Databases 69 Introduction to Web-Enabled Databases 83 PART II SQL and SQL*PLUS Basic SQL*PLUS Reports and Commands 91 Getting Text Information and Changing It 113 Playing the Numbers 141 Dates: Then, Now, and the Difference 165 10 Conversion and Transformation Functions 193 11 Grouping Things Together 205 12 When One Query Depends upon Another 219 13 Some Complex Possibilities 237 14 Building a Report in SQL*PLUS 255 15 Changing Data: insert, update, merge, and delete 279 16 Advanced Use of Functions and Variables 297 17 DECODE and CASE: if, then, and else in SQL 311 18 Creating, Dropping, and Altering Tables and Views 325 19 By What Authority? 355 20 Changing the Oracle Surroundings 379 v P:\010Comp\Oracle8\521-1\CD\Ventura\book.vp Friday, July 19, 2002 4:10:32 PM ORACLE Color profile: Generic CMYK printer profile Composite Default screen Series TIGHT / Oracle9i: The Complete Reference / Loney, Koch / 222521-1 / Chapter Blind Folio 1:1199 WIDTH_BUCKET SELECT [ WHERE condition ] UPDATE [user.]table [alias] [WHERE condition ] DESCRIPTION WHERE defines those logical conditions that will control which rows a select statement will return, a delete statement will delete, or an update statement will update A condition may be defined in one of several ways: ■ ■ ■ ■ ■ ■ ■ ■ ■ A comparison between expressions (=, >, !=, and so on) A comparison between an expression and a query A comparison between a list of expressions and a list of expressions from a query A comparison between an expression and ANY or ALL members of a list or between an expression and the values brought back from a query A test to see if an expression is IN or NOT IN a list, or the results of a query A test for being BETWEEN or NOT BETWEEN one value and another A test to see if an expression IS NULL or IS NOT NULL A test to see if there EXISTS (or NOT EXISTS) any results for a query A combination of any of the above, using the conjunctions AND and OR EXAMPLES where where where where where where where where Section >ANY ('A','C','D'); City !=ALL (select City from LOCATION); Section IN ('A','C','D'); City NOT IN (select City from LOCATION); Page BETWEEN and 7; Skill IS NULL; EXISTS (select * from WORKER where Age > 90); Section = 'A' or Section = 'B' and Page = 1; WHILE (PL/SQL) See LOOP, Chapter 27 WIDTH_BUCKET SEE ALSO FORMAT NTILE WIDTH_BUCKET ( expr , min_value , max_value , num_buckets ) DESCRIPTION WIDTH_BUCKET constructs equiwidth histograms, in which the histogram range is divided into intervals that have identical size (Compare this function with NTILE, which creates equiheight histograms.) Ideally each bucket is a “closed-open” interval of the real number line For a given expression, WIDTH_BUCKET returns the bucket number into which the value of this expression would fall after being evaluated expr is the expression (a number or datetime value) for which the histogram is being created If expr evaluates to NULL, the expression returns NULL min_value and P:\010Comp\Oracle8\521-1\CD\Ventura\ch42d.vp Thursday, July 25, 2002 3:16:04 PM 1199 ORACLE Color profile: Generic CMYK printer profile Composite Default screen 1200 Series TIGHT / Oracle9i: The Complete Reference / Loney, Koch / 222521-1 / Chapter Blind Folio 1:1200 Part VII: Alphabetical Reference max_value are expressions that resolve to the end points of the acceptable range for expr Both of these expressions must also evaluate to number or datetime values, and neither can evaluate to NULL num_buckets is an expression that resolves to a constant indicating the number of buckets This expression must evaluate to a positive integer WRAP (SQL*PLUS) See SET WRAPPING Wrapping is moving the end of a heading or title, or the contents of a column, down to a new line when it is too long to fit on one line (Contrast with TRUNCATE.) See COLUMN XML XML (eXtensible Markup Language) is a standardized syntax for describing hierarchical data XML provides a universal format for structured documents and data Its tag-based syntax gives it the flexibility to handle complex data Whereas HTML tells a Web browser how to present data, XML tells applications what the data means See Chapter 41 for examples XMLType XMLType is a datatype available as of Oracle9i to store and query XML data in the database As a type, XMLType has member functions to access, extract, and query XML data using a class of operations known as Xpath expressions The SYS_XMLGEN, SYS_XMLAGG, and DBMS_XMLGEN packages create XMLType values from existing object-relational data When you designate a column as using the XMLType datatype, Oracle will internally store the data in a CLOB datatype The following listing shows the creation of a table using the XMLType: datatype: create table MY_XML_TABLE (Key1 NUMBER, Xml_Column SYS.XMLTYPE); insert into MY_XML_TABLE (Key1, Xml_Column) values (1, SYS.XMLTYPE.CREATEXML (' Complete Reference Ending This is the end of the book. ')); You can retrieve the data from the XMLType column via the GETCLOBVAL method: select M.Xml_Column.GETCLOBVAL() as XML_Data from MY_XML_TABLE M where Key1 = 1; See Chapter 41 for additional details on XMLType and its related methods P:\010Comp\Oracle8\521-1\CD\Ventura\ch42d.vp Thursday, July 25, 2002 3:16:05 PM ... TIGHT / Oracle9 i: The Complete Reference / Loney, Koch / 222521-1 / Chapter Blind Folio 1:1200 Part VII: Alphabetical Reference max_value are expressions that resolve to the end points of the acceptable... development of Oracle databases and applications An Oracle DBA and developer since 1987, he is the primary author of numerous books, including Oracle9 i DBA Handbook, Oracle9 i Instant Scripts, and Oracle8 ... P:\010Comp \Oracle8 \521-1\CD\Ventura\book.vp Friday, July 19, 2002 4:10:31 PM ORACLE Color profile: Generic CMYK printer profile Composite Default screen Series TIGHT / Oracle9 i: The Complete Reference