You are on page 1of 0

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8/

Blind folio: i

Oracle Database 12c


The Complete Reference

00_FM.indd i

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8
Blind folio: ii

About the Authors


Bob Bryla is an Oracle 9i, 10g, and 11g Certified Professional with more than 20
years of experience in database design, database application development,
training, and Oracle database administration. He is the primary Oracle DBA and
database systems engineer at Epic in Verona, Wisconsin.
He is a technical editor for a number of Oracle Press books, including several
certification study guides for Oracle Database 10g, 11g, and 12c. He has also
been known to watch science fiction movies and tinker with Android devices in
his spare time.
Kevin Loney is an internationally recognized expert in the design, development,
administration, and tuning of Oracle databases. A technology and project group
leader 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 Contributor and Technical Editor


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.

00_FM.indd ii

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8/
Blind folio: iii

Oracle Database 12c


TheComplete Reference

Bob Bryla
Kevin Loney

New York Chicago San Francisco


Lisbon London Madrid Mexico City
Milan New Delhi San Juan
Seoul Singapore Sydney Toronto

00_FM.indd iii

8/21/13 11:04 AM

Cataloging-in-Publication Data is on file with the Library of Congress

McGraw-Hill Education books 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 pages at www.mhprofessional.com.

Oracle Database 12c: The Complete Reference


Copyright 2014 by McGraw-Hill Education (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, with the exception that the program listings may be entered,
stored, and executed in a computer system, but they may not be reproduced for publication.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. All other trademarks are the
property of their respective owners, and McGraw-Hill Education makes no claim of ownership by the
mention of products that contain these marks.
Screen displays of copyrighted Oracle software programs have been reproduced herein with the permission
of Oracle Corporation and/or its affiliates.
Excerpts of copyrighted Oracle user documentation have been reproduced herein with the permission of
Oracle Corporation and/or its affiliates.
1234567890 DOC DOC 109876543
ISBN: Book p/n 978-0-07-180172-0 and CD p/n 978-0-07-180173-7
of set 978-0-07-180175-1
MHID: Book p/n 0-07-180172-3 and CD p/n 0-07-180173-1
of set 0-07-180175-8
Sponsoring Editor
Paul Carlstroem

Copy Editor
LeeAnn Pickrell

Editorial Supervisor
Jody McKenzie

Proofreader
Susie Elkind

Illustration
Apollo Publishing Services and
Howie Severson, Fortuitous
Publishing Services

Project Editor
LeeAnn Pickrell

Indexer
Rebecca Plunkett

Art Director, Cover


Jeff Weeks

Acquisitions Coordinator
Amanda Russell

Production Supervisor
George Anderson

Technical Editor
Scott Gossett

Composition
Apollo Publishing Services

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.

00_FM.indd iv

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

To the gang at home: I couldnt have done it without you!


And the pizzas. And the rock n roll.
Bob Bryla

00_FM.indd v

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

00_FM.indd vi

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents at a Glance
PART I

Critical Database Concepts


1

Oracle Database 12c Architecture Options

.............................

Installing Oracle Database 12c and Creating a Database

Upgrading to Oracle Database 12c

Planning Oracle ApplicationsApproaches, Risks, and Standards

...................

11

....................................

21

............

41

.....................................

77

PART II

SQL and SQL*Plus


5

The Basic Parts of Speech in SQL

Basic SQL*Plus Reports and Commands

Getting Text Information and Changing It

Searching for RegularExpressions

Playing the Numbers

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

10

Dates: Then, Now, and the Difference

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

11

Conversion and Transformation Functions

12

Grouping Things Together

13

When One Query Depends on Another

14

Some Complex Possibilities

15

Changing Data: INSERT, DELETE, UPDATE, and MERGE . . . . . . . . . . . . . . . . . . . . 275

16

DECODE and CASE: IF, THEN, and ELSE in SQL

17

Creating and Managing Tables, Views, Indexes, Clusters, and Sequences

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
. . . . . . . . . . . . . . . . . . . . . . . . . . 295
. . . . . . . 311

vii

00_FM.indd vii

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

viii

Oracle Database 12c: The Complete Reference


18

Partitioning

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343

19

Basic Oracle Security

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351

PART III

Beyond the Basics


20

Advanced SecurityVirtual Private Databases

. . . . . . . . . . . . . . . . . . . . . . . . . . . 377

21

Advanced SecurityTransparent Data Encryption

22

Working with Tablespaces

23

Using SQL*Loader toLoadData

24

Using Data Pump Exportand 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

FlashbackTablesandDatabases

31

SQL Replay

. . . . . . . . . . . . . . . . . . . . . . . . 389

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533

PART IV

PL/SQL
32

An Introduction to PL/SQL

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545

33

Online Application Upgrades

34

Triggers

35

Procedures, Functions, and Packages

36

Using Native Dynamic SQL and DBMS_SQL

37

PL/SQL Tuning

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 623

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

PART V

Object-Relational Databases

00_FM.indd viii

38

Implementing Object Types, Object Views, and Methods

. . . . . . . . . . . . . . . . . . . 647

39

Collectors (Nested Tables and Varying Arrays) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663

40

Using Large Objects

41

Advanced Object-Oriented Concepts

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents at a Glance

ix

PART VI

Java in Oracle
42

An Introduction to Java

.............................................

725

43

JDBC Programming

................................................

741

44

Java Stored Procedures

.............................................

751

PART VII

Hitchhikers Guides
45

The Hitchhikers Guide to the Oracle Data Dictionary

.....................

765

46

The Hitchhikers Guide toTuning Applications andSQL

....................

821

47

The Hitchhikers Guide to SQL Result Cache and Client-Side Query Cache

.....

863

48

Case Studies in Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

877

49

The Hitchhikers Guide to Pluggable Databases

889

50

The Hitchhikers Guide to Oracle Real Application Clusters

51

The Hitchhikers Guide to Database Administration

52

The Hitchhikers Guide to XML in Oracle

..........................
.................

901

.......................

911

...............................

937

PART VIII
Alphabetical Reference

.............................................

953

...............................................

1391

...........................................................

1393

About the CD-ROM


Index

00_FM.indd ix

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8
Blind folio: x

00_FM.indd x

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
Acknowledgments

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi

PART I

Critical Database Concepts


1

..........................

Databases and Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Inside the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Storing the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Guarding the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Programmatic Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Choosing Architectures and Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Oracle Database 12c Architecture Options

5
5
7
8
8
9

...............

11

Overview of Licensing and Installation Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Installing the Oracle Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing the Grid Infrastructure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Installing Oracle Database 12c and Creating a Database

13
14
14
17

Upgrading to Oracle Database 12c

................................

21

Choosing an Upgrade Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Before Upgrading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Upgrading the Grid Infrastructure and Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Grid Infrastructure Upgrade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Database Upgrade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
After Upgrading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23
24
24
24
28
37

Planning Oracle ApplicationsApproaches, Risks, and Standards

........

41

The Cooperative Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Everyone Has Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Familiar Language of Oracle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tables of Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Structured Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43
44
45
45
46

xi

00_FM.indd xi

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xii

Oracle Database 12c: The Complete Reference


A Simple Oracle Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Why It Is Called Relational . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Some Common, Everyday Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What Are the Risks? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Importance of the New Vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Changing Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Codes, Abbreviations, and Naming Standards . . . . . . . . . . . . . . . . . . . . . . . . . .
How to Reduce the Confusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
English Names for Tables and Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
English Words for the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Capitalization in Names and Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Normalizing Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Good Design Has a Human Touch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Understanding the Application Tasks
................................
Outline of Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Understanding the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Atomic Data Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Atomic Business Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Business Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Entry
....................................................
Query and Reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Toward Object Name Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Level-Name Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Singular Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Brevity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Object Name Thesaurus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Intelligent Keys and Column Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Commandments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46
48
50
52
53
53
54
55
55
60
62
62
63
63
64
65
67
68
69
69
69
69
70
70
71
71
72
72
73
73

PART II

SQL and SQL*Plus


5

00_FM.indd xii

The Basic Parts of Speech in SQL

..................................

77

Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating the NEWSPAPER Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using SQL to Select Data from Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SELECT, FROM, WHERE, and ORDER BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Logic and Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Single-Value Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LIKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Simple Tests Against a List of Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Combining Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

79
80
80
84
86
87
90
92
94

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents

xiii

Another Use for WHERE: Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95


Single Values from a Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Lists of Values from a Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Combining Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Creating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Expanding the View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Basic SQL*Plus Reports and Commands

. . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

Building a Simple Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


REMARK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SET HEADSEP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TTITLE and BTITLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
COLUMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BREAK ON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
COMPUTE AVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SET LINESIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SET PAGESIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SET NEWPAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SPOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/* */
.........................................................
Some Clarification on Column Headings . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Other Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Command Line Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SET PAUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SAVE
........................................................
Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
HOST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding SQL*Plus Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
START
.......................................................
Checking the SQL*Plus Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Building Blocks
......................................................

Getting Text Information and Changing It

. . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What Is a String? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Concatenation ( || ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How to Cut and Paste Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
RPAD and LPAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LTRIM, RTRIM, and TRIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Combining Two Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the TRIM Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding One More Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LOWER, UPPER, and INITCAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LENGTH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xiii

108
110
111
111
112
113
113
114
115
115
116
117
117
118
118
121
122
123
123
123
124
124
125
127
130
130
132
133
134
135
136
137
139
140
140
141

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xiv

Oracle Database 12c: The Complete Reference


SUBSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
INSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ASCII and CHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using ORDER BY and WHERE withStringFunctions . . . . . . . . . . . . . . . . . . . . . . . . . .
SOUNDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
National Language Support
.......................................
Regular Expression Support
.......................................
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Searching for RegularExpressions

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

Search Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REGEXP_SUBSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REGEXP_INSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REGEXP_LIKE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REPLACE and REGEXP_REPLACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REGEXP_COUNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Playing the Numbers

156
160
162
163
164
169

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

The Three Classes of Number Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Single-Value Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Addition (+), Subtraction (), Multiplication (*),and Division (/) . . . . . . . . . . . .
NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
NVL: NULL-Value Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ABS: Absolute Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CEIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FLOOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
POWER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SQRT: Square Root . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
EXP, LN, and LOG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ROUND and TRUNC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SIGN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SIN, SINH, COS, COSH, TAN, TANH, ACOS, ATAN, ATAN2, and ASIN . . . . . .
Aggregate Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
NULLs in Group-Value Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Examples of Single- and Group-Value Functions . . . . . . . . . . . . . . . . . . . . . . . .
DISTINCT in Group Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
List Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Finding Rows with MAX or MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Precedence and Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

10

142
145
149
150
151
153
153
153

Dates: Then, Now, and the Difference

172
172
173
174
174
175
176
176
176
177
178
178
178
179
180
181
181
181
183
186
188
189
190
192

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193

Date Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194


SYSDATE, CURRENT_DATE, and SYSTIMESTAMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

00_FM.indd xiv

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
The Difference Between Two Dates
.................................
Adding Months . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Subtracting Months . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
GREATEST and LEAST
...........................................
NEXT_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LAST_DAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MONTHS_BETWEEN Two Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Combining Date Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ROUND and TRUNC in Date Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TO_DATE and TO_CHAR Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Most Common TO_CHAR Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
NEW_TIME: Switching Time Zones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TO_DATE Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dates in WHERE Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dealing with Multiple Centuries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the EXTRACT Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the TIMESTAMP Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

Conversion and Transformation Functions

Grouping Things Together

When One Query Depends on Another

228
230
231
232
233
234
236
236
238
239
239

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

Advanced Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Correlated Subqueries
...........................................
Coordinating Logical Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using EXISTS and Its Correlated Subquery . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xv

218
220
222
223
224
224
225
226

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

Using GROUP BY and HAVING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Adding an ORDER BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Order of Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Views of Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Renaming Columns with Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Power of Views of Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using ORDER BY in Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Logic in the HAVING Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using ORDER BY with Columns and Group Functions . . . . . . . . . . . . . . . . . . .
Joining Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
More Grouping Possibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

13

195
196
196
197
198
200
200
201
201
202
207
207
208
210
211
212
213

. . . . . . . . . . . . . . . . . . . . . . . . . . . 215

Elementary Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Automatic Conversion of Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A Warning About Automatic Conversion
.............................
Specialized Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Transformation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TRANSLATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DECODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

xv

242
242
244
245

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xvi

Oracle Database 12c: The Complete Reference


Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Pre-Oracle9i Syntax for Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Current Syntax for Outer Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replacing NOT IN with an Outer Join . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replacing NOT IN with NOT EXISTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Natural and Inner Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UNION, INTERSECT, and MINUS
........................................
IN Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Restrictions on UNION, INTERSECT, and MINUS . . . . . . . . . . . . . . . . . . . . . . .

14

Some Complex Possibilities

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259

Complex Groupings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Temporary Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using ROLLUP, GROUPING, and CUBE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Family Trees and CONNECT BY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Excluding Individuals and Branches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Traveling Toward the Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Finding the Leaves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Basic Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

15

Changing Data: INSERT, DELETE, UPDATE, and MERGE

.............................................................
Inserting a Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
INSERT with SELECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the APPEND Hint to Improve INSERT Performance . . . . . . . . . . . . . . . . .
ROLLBACK, COMMIT, and AUTOCOMMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using SAVEPOINTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Implicit COMMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Auto ROLLBACK
...............................................
Multitable INSERTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DELETE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UPDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UPDATE with Embedded SELECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
UPDATE with NULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MERGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Handling Errors
......................................................

DECODE and CASE: IF, THEN, and ELSE in SQL

276
277
277
278
279
280
281
281
281
285
286
287
288
289
292

. . . . . . . . . . . . . . . . . . . . . . 295

IF, THEN, ELSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Replacing Values via DECODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DECODE Within DECODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Greater Than and Less Than in DECODE
...................................
Using CASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using PIVOT
........................................................

00_FM.indd xvi

260
261
262
267
270
271
273
274

. . . . . . . . . . . . . . . . 275

INSERT

16

247
247
249
251
252
253
254
257
258

296
299
300
303
305
308

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
17

Creating and Managing Tables, Views, Indexes, Clusters, and Sequences

. . . 311

Creating a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Character Width and NUMBER Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Rounding During Insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Defining Constraints within CREATE TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . .
Designating Index Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Naming Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dropping Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Altering Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Rules for Adding or Modifying a Column . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Read-Only Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Altering Actively Used Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Virtual Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dropping a Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Table from a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating an Index-Organized Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
View Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using ORDER BY in Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Read-Only View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Enforcing Uniqueness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Unique Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Bitmap Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
When to Create an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Invisible Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Variety in Indexed Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How Many Indexes to Use on a Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Placing an Index in the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Rebuilding an Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Function-Based Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Clusters
............................................................
Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

18

Partitioning

312
313
315
316
318
319
320
320
323
324
324
324
325
326
328
329
330
331
331
332
332
333
333
334
335
335
336
336
336
337
338
338
340

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343

Creating a Partitioned Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


List Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Subpartitions
.................................................
Creating Reference and Interval Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Reference Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interval Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indexing Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Managing Partitioned Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xvii

xvii

344
346
347
348
348
348
349
350

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xviii
19

Oracle Database 12c: The Complete Reference

Basic Oracle Security

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351

Users, Roles, and Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Creating a User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Password Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Standard Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Format for the GRANT Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Revoking Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What Users Can Grant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Moving to Another User with CONNECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CREATE SYNONYM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Ungranted Privileges
.......................................
Passing Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Granting Privileges to a Role
......................................
Granting a Role to Another Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Granting a Role to Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a Password to a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Removing a Password from a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Enabling and Disabling Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Revoking Privileges from a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dropping a Role . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Granting UPDATE to Specific Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Revoking Object Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Defining Security by User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Granting Access to the Public . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Granting Access to Limited Resources
.....................................

352
352
353
357
358
358
359
361
364
364
364
366
366
367
367
368
368
369
370
370
370
370
371
372
373

PART III

Beyond the Basics


20

Advanced SecurityVirtual Private Databases

. . . . . . . . . . . . . . . . . . . . . . . 377

Initial Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Create an Application Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Create a Logon Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Create a Security Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Apply the Security Policy to Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Test the VPD Security Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How to Implement Column-Level VPD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How to Disable VPD
..................................................
How to Use Policy Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

21

Advanced SecurityTransparent Data Encryption

378
380
381
382
383
384
385
386
387

. . . . . . . . . . . . . . . . . . . . 389

Transparent Data Encryption for Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390


Setting Up TDE for Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Additional Setup for RAC Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391

00_FM.indd xviii

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
Opening and Closing the Wallet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Encrypting and Decrypting Columns
................................
Transparent Data Encryption for Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Setting Up TDE on Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating an Encrypted Tablespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

22

Working with Tablespaces

Using SQL*Loader toLoadData

Using Data Pump Exportand Import

408
409
410
413
415
416
417
418
419
421
422

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423

Creating a Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Pump Export Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Starting a Data Pump Export Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Stopping and Restarting Running Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Exporting from Another Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using EXCLUDE, INCLUDE, and QUERY . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Pump Import Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Starting a Data Pump Import Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Stopping and Restarting Running Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xix

398
399
401
401
402
402
403
403
404
404
404
405
405
405
405
405

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407

The Control File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Loading Variable-Length Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Starting the Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Logical and Physical Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Control File Syntax Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Managing Data Loads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Repeating Data Loads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tuning Data Loads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Direct Path Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SQL*Loader Express Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Additional Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

24

392
392
394
394
395

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

Tablespaces and the Structure of the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Tablespace Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
RECYCLEBIN Space in Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Read-Only Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
NOLOGGING Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Temporary Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tablespaces for System-Managed Undo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BIGFILE Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Encrypted Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Supporting the FLASHBACK DATABASE Command . . . . . . . . . . . . . . . . . . . . .
Transporting Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Planning Your Tablespace Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Separate Active and Static Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Separate Indexes and Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Separate Large and Small Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Separate Application Tables from Core Objects . . . . . . . . . . . . . . . . . . . . . . . . .

23

xix

424
424
427
428
429
430
431
435
436

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xx

Oracle Database 12c: The Complete Reference


EXCLUDE, INCLUDE, and QUERY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Generating SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437

25

Accessing Remote Data

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441

Database Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How a Database Link Works
......................................
Using a Database Link for Remote Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using a Database Link for Synonyms and Views . . . . . . . . . . . . . . . . . . . . . . . .
Using a Database Link for Remote Updates . . . . . . . . . . . . . . . . . . . . . . . . . . .
Syntax for Database Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Synonyms for Location Transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the USER Pseudo-Column in Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

26

Using Materialized Views

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453

Functionality
........................................................
Required System Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Required Table Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Read-Only vs. Updatable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CREATE MATERIALIZED VIEW Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Types of Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ROWID vs. Primary KeyBased Materialized Views . . . . . . . . . . . . . . . . . . . . .
Using Prebuilt Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indexing Materialized View Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Materialized Views toAlterQueryExecutionPaths . . . . . . . . . . . . . . . . . . . . . . .
Using DBMS_ADVISOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Refreshing Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What Kind of Refreshes Can Be Performed? . . . . . . . . . . . . . . . . . . . . . . . . . . .
FAST Refresh with CONSIDER FRESH
...............................
Automatic Refreshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Manual Refreshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CREATE MATERIALIZED VIEW Log Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Altering Materialized Views and Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dropping Materialized Views and Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

27

Using Oracle Text for Text Searches

454
454
455
455
456
460
460
460
461
461
463
465
466
469
469
470
472
473
474

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475

Adding Text to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Text Queries and Text Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Text Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Available Text Query Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Searching for an Exact Match of a Word . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Searching for an Exact Match of Multiple Words . . . . . . . . . . . . . . . . . . . . . . . .
Searching for an Exact Match of a Phrase . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Searching for Words That Are Near Each Other . . . . . . . . . . . . . . . . . . . . . . . . .
Using Wildcards During Searches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Searching for Words That Share the Same Stem . . . . . . . . . . . . . . . . . . . . . . . . .
Searching for Fuzzy Matches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xx

442
442
443
444
445
446
449
450

476
477
478
479
479
480
484
485
485
486
487

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
Searching for Words That Sound Like Other Words . . . . . . . . . . . . . . . . . . . . . .
Nesting Search Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Summarizing the Search Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the ABOUT Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Index Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Index Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

28

Using External Tables

Using Flashback Queries

FlashbackTablesandDatabases

SQL Replay

512
513
514
516
516
518
521

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523

The FLASHBACK TABLE Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Privileges Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Recovering Dropped Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Enabling and Disabling the Recycle Bin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Flashing Back to SCN or Timestamp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indexes and Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The FLASHBACK DATABASE Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

494
495
498
505
506
506
507
507
507
507
507
507
507
508
508
508

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511

Time-Based Flashback Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Saving the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SCN-Based Flashback Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What If the Flashback Query Fails? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What SCN Is Associated with Each Row? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Flashback Version Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Planning for Flashbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

30

488
488
489
490
490
491

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493

Accessing the External Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Creating an External Table
..............................................
External Table Creation Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Loading External Tables on Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Altering External Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ACCESS PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ADD COLUMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DEFAULT DIRECTORY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DROP COLUMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LOCATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
MODIFY COLUMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PARALLEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PROJECT COLUMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
REJECT LIMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
RENAME TO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Limitations, Benefits, and Potential Uses of External Tables . . . . . . . . . . . . . . . . . . . . . .

29

xxi

524
524
524
526
526
528
528

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533

High-level Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534


Isolation and Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
Creating a Workload Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535

00_FM.indd xxi

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xxii

Oracle Database 12c: The Complete Reference


Capturing the Workload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Defining Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Starting the Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Stopping the Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Exporting AWR Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Processing the Workload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replaying the Workload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Controlling and Starting the Replay Clients . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Initializing and Running the Replay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Exporting AWR Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

535
536
537
538
538
538
539
539
540
542

PART IV

PL/SQL
32

An Introduction to PL/SQL

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545

PL/SQL Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Declarations Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Executable Commands Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Conditional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CASE Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Exception Handling Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

33

Online Application Upgrades

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567

Highly Available Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Oracle Data Guard Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating the Standby Database Configuration . . . . . . . . . . . . . . . . . . . . . . . . . .
Managing RolesSwitchovers and Failovers
..........................
Making Low-Impact DDL Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Virtual Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Altering Actively Used Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding NOT NULL Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Online Object Reorganizations
....................................
Dropping a Column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34

Triggers

568
569
570
572
575
575
576
576
577
580

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581

Required System Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Required Table Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Types of Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Row-Level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Statement-Level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BEFORE and AFTER Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
INSTEAD OF Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Schema Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Database-Level Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Compound Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xxii

546
546
550
551
553
561
563

582
582
582
583
583
583
583
584
584
584

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
Trigger Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Combining DML Trigger Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Setting Inserted Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Maintaining Duplicated Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Customizing Error Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Calling Procedures Within Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Naming Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating DDL Event Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Database Event Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Compound Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Enabling and Disabling Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replacing Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dropping Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

Using Native Dynamic SQL and DBMS_SQL

PL/SQL Tuning
Tune the SQL

00_FM.indd xxiii

604
606
606
606
607
609
611
611
613
614
616
616
619
620
621
621

. . . . . . . . . . . . . . . . . . . . . . . . . 623

Using EXECUTE IMMEDIATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Using Bind Variables
..................................................
Using DBMS_SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
OPEN_CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PARSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BIND_VARIABLE and BIND_ARRAY
................................
EXECUTE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
DEFINE_COLUMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FETCH_ROWS, EXECUTE_AND_FETCH, and COLUMN_VALUE . . . . . . . . . . .
CLOSE_CURSOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

37

584
586
588
589
590
592
593
593
598
598
600
601
601

Procedures, Functions, and Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603


Required System Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Required Table Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Procedures vs. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Procedures vs. Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CREATE PROCEDURE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CREATE FUNCTION Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Referencing Remote Tables in Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Debugging Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Your Own Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Customizing Error Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Naming Procedures and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CREATE PACKAGE Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Viewing Source Code for Procedural Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Compiling Procedures, Functions, and Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Replacing Procedures, Functions, and Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dropping Procedures, Functions, and Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

36

xxiii

624
626
627
628
628
628
629
629
629
630

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xxiv

Oracle Database 12c: The Complete Reference

Steps for Tuning the PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Use PL/SQL Within SQL Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Use DBMS_PROFILER to Identify Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Use PL/SQL Features for Bulk Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
FORALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
BULK COLLECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

632
633
635
640
640
642

PART V

Object-Relational Databases
38

Implementing Object Types, Object Views, and Methods

. . . . . . . . . . . . . . . 647

Working with Object Types


.............................................
Security for Object Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indexing Object Type Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Implementing Object Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Manipulating Data via Object Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using INSTEAD OF Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Syntax for Creating Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Managing Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39

Collectors (Nested Tables and Varying Arrays)

. . . . . . . . . . . . . . . . . . . . . . . . 663

Varying Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Varying Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Describing the Varying Array
......................................
Inserting Rows into the Varying Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Selecting Data from Varying Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Nested Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Specifying Tablespaces for Nested Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Inserting Rows into a Nested Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Working with Nested Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Additional Functions for Nested Tables and Varying Arrays . . . . . . . . . . . . . . . . . . . . . .
Management Issues for Nested Tables and VaryingArrays . . . . . . . . . . . . . . . . . . . . . . .
Variability in Collectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Location of the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

40

Using Large Objects

664
664
665
666
667
670
671
672
673
675
675
676
676

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679

Available Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Specifying Storage for LOB Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Manipulating and Selecting LOB Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Initializing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using INSERT with Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Updating LOB Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using String Functions to Manipulate LOB Values . . . . . . . . . . . . . . . . . . . . . .
Using DBMS_LOB to Manipulate LOB Values . . . . . . . . . . . . . . . . . . . . . . . . .
Deleting LOBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xxiv

648
648
651
653
656
656
659
659
661

680
681
683
685
687
688
688
689
705

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
41

Advanced Object-Oriented Concepts

xxv

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707

Row Objects vs. Column Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Object Tables and OIDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Inserting Rows into Object Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Selecting Values from Object Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Updating and Deleting from Object Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the REF Function
..........................................
Using the DEREF Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the VALUE Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Invalid References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Object Views with REFs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A Quick Review of Object Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Object Views Involving References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Object PL/SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Objects in the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

708
708
709
710
711
711
712
715
716
716
716
717
720
722

PART VI

Java in Oracle
42

An Introduction to Java

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725

Java vs. PL/SQL: An Overview


...........................................
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Executable Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Conditional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

43

JDBC Programming

726
727
727
728
729
733
735
736
736

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741

Using the JDBC Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742


Using JDBC for Data Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746

44

Java Stored Procedures

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751

Loading the Class into the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


How to Access the Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Calling Java Stored Procedures Directly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Where to Perform Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

754
759
761
761

PART VII

Hitchhikers Guides
45

The Hitchhikers Guide to the Oracle Data Dictionary

. . . . . . . . . . . . . . . . . 765

A Note about Nomenclature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767


New Views Introduced in Oracle Database 12c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767

00_FM.indd xxv

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xxvi

Oracle Database 12c: The Complete Reference

New Views Introduced in Oracle Database 11g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


The Road Maps: DICTIONARY (DICT) and DICT_COLUMNS . . . . . . . . . . . . . . . . . . .
Things You Select From: Tables (and Columns), Views, Synonyms, and Sequences . . . .
Catalog: USER_CATALOG (CAT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Objects: USER_OBJECTS (OBJ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tables: USER_TABLES (TABS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Columns: USER_TAB_COLUMNS (COLS)
............................
Views: USER_VIEWS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Synonyms: USER_SYNONYMS (SYN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Sequences: USER_SEQUENCES (SEQ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Recycle Bin: USER_RECYCLEBIN and DBA_RECYCLEBIN . . . . . . . . . . . . . . . . . . . . . .
Constraints and Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Constraints: USER_CONSTRAINTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Constraint Columns: USER_CONS_COLUMNS . . . . . . . . . . . . . . . . . . . . . . . .
Constraint Exceptions: EXCEPTIONS
................................
Table Comments: USER_TAB_COMMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . .
Column Comments: USER_COL_COMMENTS . . . . . . . . . . . . . . . . . . . . . . . . .
Indexes and Clusters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indexes: USER_INDEXES (IND) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indexed Columns: USER_IND_COLUMNS . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Clusters: USER_CLUSTERS (CLU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Cluster Columns: USER_CLU_COLUMNS . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Abstract Datatypes and LOBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Abstract Datatypes: USER_TYPES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
LOBs: USER_LOBS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Database Links and Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Database Links: USER_DB_LINKS
..................................
Materialized Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Materialized View Logs: USER_MVIEW_LOGS . . . . . . . . . . . . . . . . . . . . . . . . .
Triggers, Procedures, Functions, and Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Triggers: USER_TRIGGERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Procedures, Functions, and Packages: USER_SOURCE . . . . . . . . . . . . . . . . . . .
Dimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Space Allocation and Usage, IncludingPartitionsand Subpartitions . . . . . . . . . . . . . . .
Tablespaces: USER_TABLESPACES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Space Quotas: USER_TS_QUOTAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Segments and Extents: USER_SEGMENTS andUSER_EXTENTS
............
Partitions and Subpartitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Free Space: USER_FREE_SPACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Users and Privileges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Users: USER_USERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Resource Limits: USER_RESOURCE_LIMITS . . . . . . . . . . . . . . . . . . . . . . . . . . .
Table Privileges: USER_TAB_PRIVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Column Privileges: USER_COL_PRIVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
System Privileges: USER_SYS_PRIVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xxvi

773
778
780
780
780
781
783
784
787
788
788
788
789
790
791
792
793
793
793
796
796
797
798
798
800
800
801
801
803
803
804
804
806
807
807
808
808
809
812
812
812
812
813
813
813

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Auditing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Auditing Privileges, DML, and Authentication . . . . . . . . . . . . . . . . . . . . . . . . . .
Monitoring Object Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Miscellaneous
.......................................................
Monitoring: The V$ Dynamic Performance Tables . . . . . . . . . . . . . . . . . . . . . . .
CHAINED_ROWS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PLAN_TABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Interdependencies: USER_DEPENDENCIES and IDEPTREE . . . . . . . . . . . . . . . .
DBA-Only Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Oracle Label Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
SQL*Loader Direct Load Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Globalization Support Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Heterogeneous Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Indextypes and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Outlines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Advisors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Schedulers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46

The Hitchhikers Guide toTuning Applications andSQL

814
815
815
816
817
817
817
818
818
818
818
818
819
819
819
819
820
820
820

. . . . . . . . . . . . . . . . 821

An Overview of Oracle Database Tuning Features . . . . . . . . . . . . . . . . . . . . . . . . . . . .


TuningBest Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Do as Little as Possible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Do It as Simply as Possible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tell the Database What It Needs to Know . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Maximize the Throughput in the Environment
.........................
Divide and Conquer Your Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Test Correctly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Generating and Reading Explain Plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using SET AUTOTRACE ON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using EXPLAIN PLAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Major Operations Within Explain Plans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TABLE ACCESS FULL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
TABLE ACCESS BY INDEX ROWID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Related Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Operations That Use Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
When Indexes Are Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Operations That Manipulate Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Operations That Perform Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How Oracle Handles Joins of More Than Two Tables . . . . . . . . . . . . . . . . . . . .
Parallelism and Cache Issues
......................................
Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xxvii

xxvii

822
824
824
827
828
829
830
831
833
833
838
839
839
839
840
840
842
847
854
855
861
862

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

xxviii
47

Oracle Database 12c: The Complete Reference

The Hitchhikers Guide to SQL Result Cache and Client-Side Query Cache

. 863

Database Parameter Settings for SQL Result Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . .


The DBMS_RESULT_CACHE Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dictionary Views for the SQL Result Cache
.................................
Additional Details for SQL Result Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Oracle Call Interface (OCI) Client Query Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Oracle Call Interface (OCI) Client Query Cache Restrictions . . . . . . . . . . . . . . . . . . . . .

48

Case Studies in Tuning

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877

Case Study 1: Waits, Waits, and More Waits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Case Study 2: Application-Killing Queries
..................................
Using the 10053 Trace Event
......................................
Case Study 3: Long-Running Batch Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

49

The Hitchhikers Guide to Pluggable Databases

The Hitchhikers Guide to Oracle Real Application Clusters

The Hitchhikers Guide to Database Administration

902
903
904
904
906
909
910

. . . . . . . . . . . . . . . . . . . 911

Creating a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the Oracle Enterprise Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Starting and Stopping the Database
.......................................
Sizing and Managing Memory Areas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Initialization Parameter File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Allocating and Managing Space for the Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Implications of the STORAGE Clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Table Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

00_FM.indd xxviii

890
890
891
891
892
892
895
897
898
898
898
898

. . . . . . . . . . . . . 901

Preinstallation Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Installing RAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Initialization Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Starting and Stopping RAC Instances
......................................
Transparent Application Failover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding Nodes and Instances to the Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

51

878
881
883
885

. . . . . . . . . . . . . . . . . . . . . . 889

Pluggable Database Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


Container Database Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CDB User Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Container and Pluggable Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating the Container Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Pluggable Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Managing Pluggable Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Unplugging a Pluggable Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dropping a Pluggable Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Plugging In a Pluggable Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Monitoring Pluggable Databases
...................................

50

871
872
873
874
874
875

912
913
913
914
916
917
918
920

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Contents
Index Segments
................................................
System-Managed Undo
..........................................
Temporary Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Free Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Sizing Database Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Monitoring an Undo Tablespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Automating Storage Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Configuring ASM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Segment Space Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Transporting Tablespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Generating a Transportable Tablespace Set . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Plugging in the Transportable Tablespace Set
..........................
Performing Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Pump Export and Import
.....................................
Offline Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Online Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Recovery Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

52

The Hitchhikers Guide to XML in Oracle

xxix

920
921
922
923
923
926
926
927
927
928
929
930
930
931
931
932
936
936

. . . . . . . . . . . . . . . . . . . . . . . . . . . 937

Document Type Definitions, Elements, and Attributes . . . . . . . . . . . . . . . . . . . . . . . . . .


XML Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using XSU to Select, Insert, Update, and Delete XML Values . . . . . . . . . . . . . . . . . . . .
Insert, Update, and Delete Processing with XSU . . . . . . . . . . . . . . . . . . . . . . . .
XSU and Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Customizing the Query Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using XMLType
......................................................
Other Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

938
941
944
946
947
948
949
951

PART VIII
Alphabetical Reference

About the CD-ROM


Index

00_FM.indd xxix

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1391

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1393

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

00_FM.indd xxx

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

Acknowledgments

any technical books need the expertise of more than one person, and this one is no
exception. Thanks to Kevin for his expertise on the previous editions of this book,
making it a success.

Thanks also go out to all of the people at McGraw-Hill Education who kept this book on a
reasonable schedule and learned to be even more patient with me than ever before, including
Paul Carlstroem, Amanda Russell, and Jody McKenzie. Thanks also to Scott Gossett who gave me
good advice when the theoretical met the practical. I would also be remiss if I didnt thank
LeeAnn Pickrell who inspired flashbacks to my college writing courses.
Many of my professional colleagues at Epic were a source of both inspiration and guidance:
Chris Tyne, Scott Hinman, and Lonny Niederstadt. In this case, the whole is truly greater than the
sum of its parts.
If you have any questions or comments about any part of this book, please do not hesitate to
contact me at rjbdba@gmail.com.
Bob Bryla

00_FM.indd xxxi

8/21/13 11:04 AM

Oracle TIGHT / Oracle Database 12c: The Complete Reference / BRYLA/ 180175-8

00_FM.indd xxxii

8/21/13 11:04 AM

You might also like