Creating and Running PL/SQL Code Section 2.1.. Loop Basics Section 5.2.. Making the Mostof PL/SQL Error Management Part III: PL/SQL Program Data Chapter 7... Database Event Triggers Se
Trang 2Oracle PL/SQL Programming Table of Contents
Copyright
Dedication
Preface
Objectives of This Book
Structure of This Book
Conventions Used in This Book Which Platform or Version? About the Code
Safari Enabled
Comments and Questions
Acknowledgments
Trang 3Section 1.3 So This Is PL/SQL Section 1.4 About PL/SQL Versions
Section 1.5 Resources for
PL/SQL Developers
Section 1.6 Some Words of Advice
Trang 4Chapter 2 Creating and Running PL/SQL Code
Section 2.1 SQL*Plus
Section 2.2 Performing
Essential PL/SQL Tasks Section 2.3 Calling PL/SQL from Other Languages
Chapter 3 Language
Fundamentals
Section 3.1 PL/SQL Block Structure
Section 3.2 The PL/SQL Character Set
Section 3.3 Identifiers
Trang 6Section 4.3 The GOTO
Section 5.1 Loop Basics
Section 5.2 The Simple Loop Section 5.3 The WHILE Loop Section 5.4 The Numeric FOR Loop
Section 5.5 The Cursor FOR Loop
Section 5.6 Loop Labels
Trang 7Section 5.7 Tips for Iterative Processing
Chapter 6 Exception Handlers Section 6.1 Exception-
Handling Concepts and
Trang 8Section 6.6 Making the Most
of PL/SQL Error Management Part III: PL/SQL Program Data Chapter 7 Working with
Trang 9Between Datatypes
Chapter 8 Strings
Section 8.1 String Datatypes Section 8.2 Working with Strings
Section 8.3 String Function Quick Reference
Trang 10Chapter 10 Dates and
Trang 11Section 10.7 Interval Literals Section 10.8 CAST and
EXTRACT
Section 10.9 Datetime
Arithmetic
Section 10.10 Date/Time Functions
Trang 12Section 13.1 The BOOLEAN Datatype
Section 13.2 The RAW
Datatype
Section 13.3 The UROWID
Trang 13and ROWID Datatypes
Section 13.4 The LOB
Section 14.3 Transaction
Trang 14Management
Section 14.4 Autonomous Transactions
Chapter 15 Data Retrieval Section 15.1 Cursor Basics Section 15.2 Working with Implicit Cursors
Section 15.3 Working with Explicit Cursors
Trang 15and REF CURSORs
Trang 16Section 16.6 When to Use DBMS_SQL
Section 16.7 NDS Utility Package
Part V: PL/SQL Application Construction
Chapter 17 Procedures,
Functions, and Parameters Section 17.1 Modular Code Section 17.2 Procedures Section 17.3 Functions
Section 17.4 Parameters Section 17.5 Local Modules Section 17.6 Module
Trang 18Section 18.5 When to Use Packages
Section 18.6 Packages and Object Types
Chapter 19 Triggers
Section 19.1 DML Triggers Section 19.2 DDL Triggers Section 19.3 Database Event Triggers
Section 19.4 INSTEAD OF Triggers
Section 19.5 AFTER
SUSPEND Triggers
Section 19.6 Maintaining
Trang 19Triggers
Chapter 20 Managing PL/SQL Code
Section 20.1 Managing Code
in the Database
Section 20.2 Using Native
Compilation
Section 20.3 Using the
Optimizing Compiler and
Compile-Time Warnings
Section 20.4 Conditional
Compilation
Section 20.5 Testing PL/SQL Programs
Trang 20Section 20.6 Debugging
PL/SQL Programs
Section 20.7 Tuning PL/SQL Programs
Section 20.8 Protecting Stored Code
Chapter 21 I/O and PL/SQL Section 21.1 Displaying
Trang 21Section 21.5 Other Types of I/O Available in PL/SQL
Part VI: Advanced PL/SQL Topics
Section 22.4 Application Contexts
Section 22.5 Fine-Grained
Trang 22Auditing
Chapter 23 Inside PL/SQL Section 23.1 Looking Under the Hood
Section 23.2 PL/SQL's
Optimizing Compiler
Section 23.3 Dependency Management
Section 23.4 Execution
Authority Models
Section 23.5 PL/SQL and Oracle Memory
Section 23.6 Server-Side PL/SQL Processing: Reprise
Trang 23Section 23.7 What You Need
Trang 24Conversion
Section 24.8 Globalization
Development Kit for PL/SQL Chapter 25 Object-Oriented Aspects of PL/SQL
Section 25.1 Introduction to Oracle's Object Features
Section 25.2 An Extended Example
Section 25.3 Object Views Section 25.4 Maintaining
Object Types and Object Views Section 25.5 Pontifications Chapter 26 Calling Java from
Trang 25PL/SQL
Section 26.1 Oracle and Java Section 26.2 Getting Ready to Use Java in Oracle
Section 26.3 A Simple
Demonstration
Section 26.4 Using loadjava Section 26.5 Using dropjava Section 26.6 Managing Java in the Database
Section 26.7 Using
DBMS_JAVA
Section 26.8 Publishing and Using Java in PL/SQL
Trang 26Chapter 27 External
Procedures
Section 27.1 Introduction to External Procedures
Section 27.2 The Oracle Net Configuration
Section 27.3 Setting Up
Multithreaded Mode
Section 27.4 Creating an Oracle Library
Section 27.5 Writing the Call Specification
Section 27.6 Raising an
Exception from the Called C
Trang 28Appendix C Date Format Models
Trang 30V
W
X
Y Z
Trang 31Oracle PL/SQL Programming
By Steven Feuerstein, Bill Pribyl
Publisher: O'Reilly
Pub Date: August 2005
ISBN: 0-596-00977-1
Pages: 1198
Table of Contents | Index
For the past ten years, O'Reilly's Oracle PL/SQL
Programming has been the bestselling book on
PL/SQL, Oracle's powerful procedural language.
Packed with examples and helpful recommendations, the
book has helped everyone from novices to experienced
developers, and from Oracle Forms developers to
Trang 32database administrators make the most of PL/SQL.
The fourth edition is a comprehensive update, adding significant new content and extending coverage to include the very latest Oracle version, Oracle Database
10g Release 2 It describes such new features as the
PL/SQL optimizing compiler, conditional compilation, compile-time warnings, regular expressions, set
operators for nested tables, nonsequential collections in FORALL, the programmer-defined quoting mechanism, the ability to backtrace an exception to a line number, a variety of new built-in packages, and support for IEEE
754 compliant floating-point numbers.
The new edition adds brand-new chapters on security (including encryption, row-level security, fine-grained auditing, and application contexts), file, email, and web I/O (including the built-in packages DBMS_OUTPUT, UTL_FILE, UTL_MAIL, UTL_SMTP, and
UTL_HTTP) and globalization and localization.
Trang 33Co-authored by the world's foremost PL/SQL authority, Steven Feuerstein, this classic reference provides language syntax, best practices, and extensive code, ranging from simple examples to complete applications making it a must-have on your road to PL/SQL mastery.
A companion web site contains many more examples and additional technical content for enhanced learning.
Trang 34Oracle PL/SQL Programming
By Steven Feuerstein, Bill Pribyl
Publisher: O'Reilly
Pub Date: August 2005
Objectives of This Book
Structure of This Book
Trang 35Conventions Used in This Book
Which Platform or Version?
About the Code
Section 1.2 The Origins of PL/SQL Section 1.3 So This Is PL/SQL
Section 1.4 About PL/SQL Versions Section 1.5 Resources for PL/SQL
Trang 36Languages
Chapter 3 Language Fundamentals Section 3.1 PL/SQL Block Structure Section 3.2 The PL/SQL Character Set Section 3.3 Identifiers
Part II: PL/SQL Program Structure
Chapter 4 Conditional and Sequential
Loops
Trang 37Section 5.1 Loop Basics
Section 5.2 The Simple Loop
Section 5.3 The WHILE Loop
Section 5.4 The Numeric FOR Loop Section 5.5 The Cursor FOR Loop Section 5.6 Loop Labels
Section 5.7 Tips for Iterative Processing Chapter 6 Exception Handlers
Section 6.1 Exception-Handling Concepts
and Terminology
Section 6.2 Defining Exceptions
Section 6.3 Raising Exceptions
Section 6.4 Handling Exceptions
Section 6.5 Building an Effective Error
Management Architecture
Section 6.6 Making the Most of PL/SQL
Error Management
Part III: PL/SQL Program Data
Chapter 7 Working with Program Data Section 7.1 Naming Your Program Data
Trang 38Section 8.1 String Datatypes
Section 8.2 Working with Strings Section 8.3 String Function Quick
Reference
Chapter 9 Numbers
Section 9.1 Numeric Datatypes
Section 9.2 Number Conversions Section 9.3 Numeric Functions
Chapter 10 Dates and Timestamps Section 10.1 Datetime Datatypes Section 10.2 Getting the Date and Time Section 10.3 Interval Datatypes
Section 10.4 Datetime Conversions
Trang 39Section 10.5 Date and Timestamp
Section 11.1 Records in PL/SQL Chapter 12 Collections
Section 12.1 Collections Overview Section 12.2 Collection Methods (Built-
Trang 40Section 13.3 The UROWID and
Section 15.1 Cursor Basics
Section 15.2 Working with Implicit
Cursors
Section 15.3 Working with Explicit
Cursors
Section 15.4 BULK COLLECT
Section 15.5 SELECT FOR UPDATE
Trang 41Section 15.6 Cursor Variables and REF
CURSORs
Section 15.7 Cursor Expressions
Chapter 16 Dynamic SQL and Dynamic
PL/SQL
Section 16.1 NDS Statements
Section 16.2 Binding Variables
Section 16.3 Working with Objects and
Collections
Section 16.4 Dynamic PL/SQL
Section 16.5 Recommendations for NDS Section 16.6 When to Use DBMS_SQL Section 16.7 NDS Utility Package Part V: PL/SQL Application Construction Chapter 17 Procedures, Functions, and
Trang 42Section 17.5 Local Modules
Section 17.6 Module Overloading
Section 17.7 Forward Declarations Section 17.8 Advanced Topics
Section 17.9 Go Forth and Modularize! Chapter 18 Packages
Section 18.1 Why Packages?
Section 18.2 Rules for Building Packages Section 18.3 Rules for Calling Packaged
Elements
Section 18.4 Working with Package Data Section 18.5 When to Use Packages Section 18.6 Packages and Object Types Chapter 19 Triggers
Section 19.1 DML Triggers
Section 19.2 DDL Triggers
Section 19.3 Database Event Triggers Section 19.4 INSTEAD OF Triggers Section 19.5 AFTER SUSPEND
Triggers
Trang 43Section 19.6 Maintaining Triggers Chapter 20 Managing PL/SQL Code Section 20.1 Managing Code in the
Programs
Section 20.7 Tuning PL/SQL Programs Section 20.8 Protecting Stored Code Chapter 21 I/O and PL/SQL
Section 21.1 Displaying Information
Section 21.2 Reading and Writing Files Section 21.3 Sending Email
Section 21.4 Working with Web-Based
Data (HTTP)
Section 21.5 Other Types of I/O
Available in PL/SQL
Trang 44Part VI: Advanced PL/SQL Topics
Chapter 22 Application Security and
Section 23.1 Looking Under the Hood Section 23.2 PL/SQL's Optimizing
Compiler
Section 23.3 Dependency Management Section 23.4 Execution Authority Models Section 23.5 PL/SQL and Oracle
Trang 45Section 24.1 Overview and Terminology Section 24.2 Unicode Primer
Section 24.3 Character Semantics Section 24.4 String Sort Order
Section 24.5 Multilingual Information
Section 25.1 Introduction to Oracle'sObject Features
Section 25.2 An Extended Example Section 25.3 Object Views
Section 25.4 Maintaining Object Types
and Object Views
Section 25.5 Pontifications
Chapter 26 Calling Java from PL/SQL
Trang 46Section 26.1 Oracle and Java
Section 26.2 Getting Ready to Use Java
in Oracle
Section 26.3 A Simple Demonstration Section 26.4 Using loadjava
Section 26.5 Using dropjava
Section 26.6 Managing Java in the
Database
Section 26.7 Using DBMS_JAVA Section 26.8 Publishing and Using Java in
PL/SQL
Chapter 27 External Procedures
Section 27.1 Introduction to External
Procedures
Section 27.2 The Oracle NetConfiguration
Section 27.3 Setting Up Multithreaded
Mode
Section 27.4 Creating an Oracle Library Section 27.5 Writing the Call
Specification
Trang 47Section 27.6 Raising an Exception from
the Called C Program
Section 27.7 Nondefault Agents Section 27.8 Maintaining External
Procedures
Part VII: Appendixes
Appendix A Regular Expression
Metacharacters and Function Parameters Section A.1 Metacharacters
Section A.2 Function Parameters Appendix B Number Format Models Appendix C Date Format Models Colophon
About the Authors
Colophon
Index
Trang 48Oracle PL/SQL Programming, Fourth Edition
by Steven Feuerstein with Bill Pribyl
Copyright © 2005, 2002, 1997, 1995O'Reilly Media, Inc All rights reserved.Printed in the United States of America
Published by O'Reilly Media, Inc., 1005Gravenstein Highway North, Sebastopol,
CA 95472
O'Reilly Media, Inc books may be
purchased for educational, business, orsales promotional use Online editions arealso available for most titles
(safari.oreilly.com) For more
Trang 49information, contact our
corporate/institutional sales department:(800) 998-9938 or
corporate@oreilly.com
Editors: Deborah Russell
Production Editor: Mary Anne Weeks Mayo
Interior Designer: David Futato
Printing History:
September 1995: First Edition.
September 1997: Second Edition.
Trang 50September 2002: Third Edition.
August 2005: Fourth Edition.
Nutshell Handbook, the Nutshell
Handbook logo, and the O'Reilly logo areregistered trademarks of O'Reilly Media,
Inc Oracle PL/SQL Programming,
Fourth Edition, the image of ants, andrelated trade dress are trademarks ofO'Reilly Media, Inc Many of the
designations used by manufacturers andsellers to distinguish their products areclaimed as trademarks Where thosedesignations appear in this book, and
Trang 51O'Reilly Media Inc., was aware of atrademark claim, the designations havebeen printed in caps or initial caps.
Oracle® and all Oracle-based trademarksand logos are trademarks or registeredtrademarks of Oracle Corporation, Inc., inthe United States and other countries.O'Reilly Media, Inc., is independent ofOracle Corporation Java™ and all Java-based trademarks and logos are
trademarks or registered trademarks ofSun Microsystems, Inc., in the UnitedStates and other countries O'Reilly
Media, Inc., is independent of Sun
Microsystems, Inc Microsoft®,
Windows®, and all Microsoft-basedtrademarks and logos are trademarks or
Trang 52registered trademarks of Microsoft, Inc.,
in the United States and other countries.O'Reilly Media, Inc is independent ofMicrosoft, Inc
While every precaution has been taken inthe preparation of this book, the publisherand authors assume no responsibility forerrors or omissions, or for damages
resulting from the use of the informationcontained herein
ISBN: 0-596-00977-1
[M]
Trang 53To my wife, Veva Silva
Steven Feuerstein
To my father, who told me
"that's no hill for a stepper" enough times that it finally sank in.
To my parents, Rolla and Ranae Windley, for giving me the freedom to explore.
Trang 54Bill Pribyl
Trang 55Millions of application developers anddatabase administrators around the worlduse software provided by Oracle
Corporation to build complex systems thatmanage vast quantities of data At theheart of much of Oracle's software isPL/SQLa programming language thatprovides procedural extensions to
Oracle's version of SQL (Structured
Query Language) and serves as the
programming language within the OracleDeveloper toolset (most notably FormsDeveloper and Reports Developer)
PL/SQL figures prominently as an
enabling technology in almost every new