Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596514464/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Preface
Millions of application developers and database administrators around the world use software provided by Oracle Corporation to build complex systems that manage vast quantities of data. At the heart of much of Oracles software is PL/SQLa programming language that provides procedural extensions to Oracles version of SQL (Structured Query Language) and serves as the programming language within the Oracle Developer toolset (most notably Forms Developer and Reports Developer).
PL/SQL figures prominently as an enabling technology in almost every new product released by Oracle Corporation. Software professionals use PL/SQL to perform many kinds of programming functions, including:
Implementing crucial business rules in the Oracle Server with PL/SQL-based stored procedures and database triggers
Generating and managing XML documents entirely within the database
Linking web pages to an Oracle database
Implementing and automating database administration tasksfrom establishing row-level security to managing rollback segments within PL/SQL programs
PL/SQL was modeled after Ada,] a programming language designed for the U.S. Department of Defense. Ada is a high-level language that emphasizes data abstraction, information hiding, and other key elements of modern design strategies. As a result of this very smart design decision by Oracle, PL/SQL is a powerful language that incorporates many of the most advanced elements of procedural languages, including:
A full range of datatypes from number to string, and including complex data structures such as records (which are similar to rows in a relational table), collections (which are Oracles version of arrays), and XMLType (for managing XML documents in Oracle and through PL/SQL)
An explicit and highly readable block structure that makes it easy to enhance and maintain PL/SQL applications
Conditional, iterative, and sequential control statements, including a CASE statement and three different kinds of loops
Exception handlers for use in event-based error handling
Named, reusable code elements such as functions, procedures, triggers, object types (akin to object-oriented classes), and packages (collections of related programs and variables)
PL/SQL is integrated tightly into Oracles SQL language: you can execute SQL statements directly from your procedural program without having to rely on any kind of intermediate API (Application Programming Interface) such as JDBC (Java Database Connectivity) or ODBC (Open Database Connectivity). Conversely, you can also call your own PL/SQL functions from within a SQL statement.
Oracle developers who want to be successful in the 21st century must learn to use PL/SQL to full advantage. This is a two-step process. First, you must become familiar with and learn how to use the languages ever-expanding set of features; and second, after gaining competence in the individual features, you must learn how to put these constructs together to build complex applications.
For these reasons and more, Oracle developers need a solid, comprehensive resource for the base PL/SQL language. You need to know the basic building blocks of PL/SQL, but you also need to learn by example so that you can avoid some of the trial and error. As with any programming language, PL/SQL has a right way and many wrong ways (or at least not as right ways) to handle just about any task. It is my hope that this book will help you learn how to use the PL/SQL language in the most effective and efficient way possible.
[ for more information about Ada.
Objectives of This Book
What, specifically, will this book help you do?
Take full advantage of PL/SQL
Oracles reference manuals may describe all the features of the PL/SQL language, but they dont tell you how to apply the technology. In fact, in some cases, youll be lucky to even understand how to use a given feature after youve made your way through the railroad diagrams. Books and training courses tend to cover the same standard topics in the same limited way. In this book, Ill venture beyond the basics to the far reaches of the language, finding the nonstandard ways that a particular feature can be tweaked to achieve a desired result.
Use PL/SQL to solve your problems
You dont spend your days and nights writing PL/SQL modules so that you can rise to a higher plane of existence. You use PL/SQL to solve problems for your company or your customers. In this book, I try hard to help you tackle real-world problems, the kinds of issues developers face on a daily basis (at least those problems that can be solved with mere software). To do this, Ive packed the book with examplesnot just small code fragments, but substantial application components that you can apply immediately to your own situations. There is a good deal of code in the book itself, and much more on the accompanying web site. In a number of cases, I use the code examples to guide you through the analytical process needed to come up with a solution. In this way youll see, in the most concrete terms, how to apply PL/SQL features and undocumented applications of those features to a particular situation.
Write efficient, maintainable code
PL/SQL and the rest of the Oracle products offer the potential for incredible development productivity. If you arent careful, however, this capability will simply let you dig yourself into a deeper, darker hole than youve ever found yourself in before. I would consider this book a failure if it only helped programmers write more code in less time; I want to help you develop the skills and techniques to build applications that readily adapt to change and that are easily understood and maintained. I want to teach you to use comprehensive strategies and code architectures that allow you to apply PL/SQL in powerful, general ways to the problems you face.
Structure of This Book
Both the authors and OReilly Media are committed to providing comprehensive, useful coverage of PL/SQL over the life of the language. This fifth edition of Oracle PL/SQL Programming describes the features and capabilities of PL/SQL up through Oracle Database 11 g Release 2. I assume for this edition that Oracle Database 11