Oracle Advanced PL/SQL Developer Professional Guide
4/5
()
About this ebook
PL/SQL (Procedural Language/Structured Query Language) is Oracle Corporation's procedural extension language for SQL and the Oracle relational database. Server-side PL/SQL is stored and compiled in the Oracle Database and runs within the Oracle executable. With this guide Oracle developers can work towards accomplishing Oracle 11g Advanced PL/SQL Professional certification, which is the second milestone for developers working at the Associate level.
The Oracle Advanced PL/SQL Developer Professional Guide helps you master advanced PL/SQL concepts. Besides the clear and precise explanation on advanced topics, it also contains example code and demonstrations, which gives a sense of application and usage to readers.
The book gives a deep insight that will help transform readers from mid-level programmers to professional database developers. It aims to cover the advanced features of PL/SQL for designing and optimizing PL/SQL code.
This book starts with an overview of PL/SQL as the programming database language and outlines the benefits and characteristics of the language. The book then covers the advanced features that include PL/SQL code writing using collections, tuning recommendations using result caching, implementing VPD to enforce row level security, and much more. Apart from programming, the book also dives deep into the usage of the development tool SQL Developer, employing best practices in database environments and safeguarding the vulnerable areas in PL/SQL code to avoid code injection.
ApproachThis book is packed with real world examples that cover all the advanced features of PL/SQL. In turn, each major certification topic is covered in a separate chapter that makes understanding concepts easier. At the end of each chapter, you will find plenty of practice questions to strengthen and test your learning.
Who this book is forIf you are a PL/SQL developer looking for deeper insight and a move from mid-level programmer to professional database developer, then this is the best guide for you.
This book is also an ideal guide for all the Associate level PL/SQL programmers who are preparing for the Professional 1Z0-146 certification.
This book assumes you have prior knowledge of PL/SQL programming.
Saurabh K. Gupta
Since the time Saurabh Gupta was introduced to Oracle database by chance and not by choice, he has been synchronizing his on job and off job interests with Oracle database programming. As an Oracle 11g Certified Advanced PL/SQL Professional, he soon moved from programming to database designing, development, and administration. During the phase when he specialized in database modelling, development and tuning, he was an active Oracle blogger and OTN forum member. To date, he has authored more than 70 online articles and papers. His works can be noted at RMOUG SQL> Update journal, PSOUG (http://www.psoug.org), DBANOTES (http://www.dbanotes.com), EXFORSYS (http://www.exforsys.com), and CLUB-ORACLE (http://www.club-oracle.com). He shares his technical encounters in Oracle technologies on his own blogging venture http://sbhoracle.wordpress.com/. He is an AIOUG (All India Oracle Users Group) member and loves to participate in technical meets and conferences. Besides digging into Oracle, sketching and snooker are other past times for him. One can reach him through his blog SbhOracle for any comments, suggestions or feedback regarding this book.
Related to Oracle Advanced PL/SQL Developer Professional Guide
Related ebooks
Advanced Oracle PL/SQL Developer's Guide - Second Edition Rating: 4 out of 5 stars4/5Oracle SQL Developer Rating: 0 out of 5 stars0 ratingsLearning Oracle 12c: A PL/SQL Approach Rating: 0 out of 5 stars0 ratingsSQL Server 2014 Development Essentials Rating: 5 out of 5 stars5/5Oracle SQL Developer 2.1 Rating: 0 out of 5 stars0 ratingsGetting Started with Oracle Data Integrator 11g: A Hands-On Tutorial Rating: 5 out of 5 stars5/5SQL Server 2016 Developer's Guide Rating: 0 out of 5 stars0 ratingsIntroduction to Oracle Database Administration Rating: 5 out of 5 stars5/5SQL Tutorial For Beginners Rating: 0 out of 5 stars0 ratingsSecuring SQL Server: Protecting Your Database from Attackers Rating: 0 out of 5 stars0 ratingsLearning PostgreSQL Rating: 1 out of 5 stars1/5The SQL Workshop: Learn to create, manipulate and secure data and manage relational databases with SQL Rating: 0 out of 5 stars0 ratingsOracle Database 12c Backup and Recovery Survival Guide Rating: 5 out of 5 stars5/5Oracle Data Guard 11gR2 Administration Beginner's Guide Rating: 0 out of 5 stars0 ratingsOracle Business Intelligence Enterprise Edition 12c - Second Edition Rating: 0 out of 5 stars0 ratingsOCA Oracle Database 11g Database Administration I: A Real-World Certification Guide Rating: 4 out of 5 stars4/5Oracle GoldenGate 11g Implementer's guide Rating: 5 out of 5 stars5/5Learning Informatica PowerCenter 9.x Rating: 3 out of 5 stars3/5Oracle GoldenGate 12c Implementer's Guide Rating: 0 out of 5 stars0 ratingsOCA Oracle Database 11g Administration I Exam Guide (Exam 1Z0-052) Rating: 0 out of 5 stars0 ratingsOCP Oracle Certified Professional Java SE 11 Programmer II Study Guide: Exam 1Z0-816 and Exam 1Z0-817 Rating: 5 out of 5 stars5/5PostgreSQL Server Programming Rating: 0 out of 5 stars0 ratingsJDBC: Practical Guide for Java Programmers Rating: 0 out of 5 stars0 ratingsOracle Quick Guides: Part 3 - Coding in Oracle: SQL and PL/SQL Rating: 0 out of 5 stars0 ratingsOracle SQL: Jumpstart with Examples Rating: 5 out of 5 stars5/5Oracle Database 12c Quickstart Rating: 5 out of 5 stars5/5Mastering PL/SQL Through Illustrations: From Learning Fundamentals to Developing Efficient PL/SQL Blocks (English Edition) Rating: 0 out of 5 stars0 ratingsOracle Database 12c Release 2 Testing Tools and Techniques for Performance and Scalability Rating: 5 out of 5 stars5/5Oracle SQL and PL/SQL Rating: 5 out of 5 stars5/5Oracle Database 12c Release 2 New Features Rating: 0 out of 5 stars0 ratings
Applications & Software For You
Adobe Illustrator: A Complete Course and Compendium of Features Rating: 0 out of 5 stars0 ratingsAudio Engineering: Know It All Rating: 5 out of 5 stars5/5Adobe Photoshop: A Complete Course and Compendium of Features Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Adobe InDesign CC: A Complete Course and Compendium of Features Rating: 0 out of 5 stars0 ratingsBlender 3D Basics Beginner's Guide Second Edition Rating: 5 out of 5 stars5/5The Best Hacking Tricks for Beginners Rating: 4 out of 5 stars4/5Mastering QuickBooks 2020: The ultimate guide to bookkeeping and QuickBooks Online Rating: 0 out of 5 stars0 ratingsHow Do I Do That In InDesign? Rating: 5 out of 5 stars5/5How to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally Rating: 4 out of 5 stars4/5Adobe Premiere Pro: A Complete Course and Compendium of Features Rating: 0 out of 5 stars0 ratingsLearn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Digital Video Production Handbook Rating: 0 out of 5 stars0 ratingsSix Figure Blogging In 3 Months Rating: 4 out of 5 stars4/5Adobe Illustrator CC For Dummies Rating: 5 out of 5 stars5/5Vocal Rescue: Rediscover the Beauty, Power and Freedom in Your Singing Rating: 4 out of 5 stars4/5GarageBand For Dummies Rating: 5 out of 5 stars5/5FL Studio Cookbook Rating: 4 out of 5 stars4/5The Basics of User Experience Design by Interaction Design Foundation Rating: 4 out of 5 stars4/5The Chromebook Infused Classroom: Using Blended Learning to Create Engaging, Student-Centered Classrooms Rating: 0 out of 5 stars0 ratingsThe Essential Persona Lifecycle: Your Guide to Building and Using Personas Rating: 4 out of 5 stars4/5Essential Affinity Photo 2 Rating: 0 out of 5 stars0 ratingsData Science and Big Data Analytics: Discovering, Analyzing, Visualizing and Presenting Data Rating: 0 out of 5 stars0 ratingsPhotoshop For Beginners: Learn Adobe Photoshop cs5 Basics With Tutorials Rating: 0 out of 5 stars0 ratingsThe Little SAS Book: A Primer, Sixth Edition Rating: 5 out of 5 stars5/5The Most Concise Step-By-Step Guide To ChatGPT Ever Rating: 3 out of 5 stars3/5
Reviews for Oracle Advanced PL/SQL Developer Professional Guide
8 ratings0 reviews
Book preview
Oracle Advanced PL/SQL Developer Professional Guide - Saurabh K. Gupta
Table of Contents
Oracle Advanced PL/SQL Developer Professional Guide
Credits
Foreword
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Instant Updates on New Packt Books
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Overview of PL/SQL Programming Concepts
PL/SQL — the procedural aspect
My first PL/SQL program
PL/SQL development environments
SQL Developer
SQL Developer — the history
Creating a connection
SQL Worksheet
Executing a SQL statement
Calling a SQL script from SQL Developer
Creating and executing an anonymous PL/SQL block
Debugging the PL/SQL code
Editing and saving the scripts
SQL*Plus
Executing a SQL statement in SQL*Plus
Executing an anonymous PL/SQL block
Procedures
Executing a procedure
Functions
Function—execution methods
Restrictions on calling functions from SQL expressions
PL/SQL packages
Cursors—an overview
Cursor execution cycle
Cursor attributes
Cursor FOR loop
Exception handling in PL/SQL
System-defined exceptions
User-defined exceptions
The RAISE_APPLICATION_ERROR procedure
Exception propagation
Managing database dependencies
Displaying the direct and indirect dependencies
Dependency metadata
Dependency issues and enhancements
Reviewing Oracle-supplied packages
Summary
Practice exercise
2. Designing PL/SQL Code
Understanding cursor structures
Cursor execution cycle
Cursor design considerations
Cursor design—guidelines
Cursor attributes
Implicit cursors
Explicit cursors
Cursor variables
Ref cursor types—strong and weak
SYS_REFCURSOR
Processing a cursor variable
Cursor variables as arguments
Cursor variables—restrictions
Subtypes
Subtype classification
Oracle's predefined subtypes
User-defined subtypes
Type compatibility with subtypes
Summary
Practice exercise
3. Using Collections
Collections—an overview
Categorization
Selecting an appropriate collection type
Associative arrays
Nested tables
Nested table collection type as the database object
DML operations on nested table columns
Inserting a nested table instance
Selecting a nested table column
Updating the nested table instance
A nested table collection type in PL/SQL
Additional features of a nested table
Varray
Varray in PL/SQL
Varray as a database collection type
DML operations on varray type columns
Inserting a varray collection type instance
Selecting a varray column
Updating the varray instance
Collections—a comparative study
Common characteristics of collection types
Nested table versus associative arrays
Nested table versus varrays
PL/SQL collection methods
EXISTS
COUNT
LIMIT
FIRST and LAST
PRIOR and NEXT
EXTEND
TRIM
DELETE
Manipulating collection elements
Collection initialization
Summary
Practice exercise
4. Using Advanced Interface Methods
Understanding external routines
Architecture of external routines
Oracle Net Configuration
TNSNAMES.ora
LISTENER.ora
Oracle Net Configuration verification
Benefits of external procedures
Executing external C programs from PL/SQL
Executing C program through external procedure—development steps
Executing Java programs from PL/SQL
Calling a Java class method from PL/SQL
Uploading a Java class into the database—development steps
The loadjava utility—an illustration
Creating packages for Java class methods
Summary
Practice exercise
5. Implementing VPD with Fine Grained Access Control
Fine Grained Access Control
Overview
Virtual Private Database—the alias
How FGAC or VPD works?
Salient features of VPD
VPD implementation—outline and components
Application context
Policy function definition and implementation of row-level security
Associating a policy using the DBMS_RLS package
VPD implementation—demonstrations
Assignment 1—implementing VPD using simple security policy
Assignment 2—implementing VPD using an application context
VPD policy metadata
Policy utilities—refresh and drop
Summary
Practice exercise
6. Working with Large Objects
Introduction to the LOB data types
Internal LOB
External LOB
Understanding the LOB data types
LOB value and LOB locators
BLOB or CLOB!
BFILE
Temporary LOBs
Creating LOB data types
Directories
Creating LOB data type columns in a table
Managing LOB data types
Managing internal LOBs
Securing and managing BFILEs
The DBMS_LOB package—overview
Security model
DBMS_LOB constants
DBMS_LOB data types
DBMS_LOB subprograms
Rules and regulations
Internal LOBs
BFILEs
Working with the CLOB, BLOB, and BFILE data types
Initializing LOB data type columns
Inserting data into a LOB column
Populating a LOB data type using an external file
Selecting LOB data
Modifying the LOB data
Delete LOB data
Miscellaneous LOB notes
LOB column states
Locking a row containing LOB
Opening and closing LOBs
Accessing LOBs
LOB restrictions
Migrating from LONG to LOB
Using temporary LOBs
Temporary LOB operations
Managing temporary LOBs
Validating, creating, and freeing a temporary LOB
Summary
Practice exercise
7. Using SecureFile LOBs
Introduction to SecureFiles
SecureFile LOB—an overview
Architectural enhancements in SecureFiles
SecureFile LOB features
Working with SecureFiles
SecureFile metadata
Enabling advanced features in SecureFiles
Deduplication
Compression
Encryption
Migration from BasicFiles to SecureFiles
Online Redefinition method
Summary
Practice exercise
8. Compiling and Tuning to Improve Performance
Native and interpreted compilation techniques
Real native compilation
Selecting the appropriate compilation mode
When to choose interpreted compilation mode?
When to choose native compilation mode?
Setting the compilation mode
Querying the compilation settings
Compiling a program unit for a native or interpreted compilation
Compiling the database for PL/SQL native compilation (NCOMP)
Tuning PL/SQL code
Comparing SQL and PL/SQL
Avoiding implicit data type conversion
Understanding the NOT NULL constraint
Using the PLS_INTEGER data type for arithmetic operations
Using a SIMPLE_INTEGER data type
Modularizing the PL/SQL code
Using bulk binding
Using SAVE_EXCEPTIONS
Rephrasing the conditional control statements
Conditions with an OR logical operator
Conditions with an AND logical operator
Enabling intra unit inlining
PLSQL_OPTIMIZE_LEVEL—the Oracle initialization parameter
Case 1—PLSQL_OPTIMIZE_LEVEL = 0
Case 2—PLSQL_OPTIMIZE_LEVEL = 1
Case 3—PLSQL_OPTIMIZE_LEVEL = 2
Case 4—PLSQL_OPTIMIZE_LEVEL = 3
PRAGMA INLINE
Summary
Practice exercise
9. Caching to Improve Performance
Introduction to result cache
Server-side result cache
SQL query result cache
PL/SQL function result cache
OCI client results cache
Configuring the database for the server result cache
The DBMS_RESULT_CACHE package
Implementing the result cache in SQL
Manual result cache
Automatic result cache
Result cache metadata
Query result cache dependencies
Cache memory statistics
Invalidation of SQL result cache
Displaying the result cache memory report
Read consistency of the SQL result cache
Limitation of SQL result cache
Implementing result cache in PL/SQL
The RESULT_CACHE clause
Cross-session availability of cached results
Invalidation of PL/SQL result cache
Limitations of PL/SQL function result cache
Argument and return type restrictions
Function structural restrictions
Summary
Practice exercise
10. Analyzing PL/SQL Code
Track coding information
[DBA | ALL | USER]_ARGUMENTS
[DBA | ALL | USER]_OBJECTS
[DBA | ALL | USER]_SOURCE
[DBA | ALL | USER]_PROCEDURES
[DBA | ALL | USER]_DEPENDENCIES
Using SQL Developer to find coding information
The DBMS_DESCRIBE package
DBMS_UTILITY.FORMAT_CALL_STACK
Tracking propagating exceptions in PL/SQL code
Determining identifier types and usages
The PL/Scope tool
The PL/Scope identifier collection
The PL/Scope report
Illustration
Applications of the PL/Scope report
The DBMS_METADATA package
DBMS_METADATA data types and subprograms
Parameter requirements
The DBMS_METADATA transformation parameters and filters
Working with DBMS_METADATA—illustrations
Case 1—retrieve the metadata of a single object
Case 2—retrieve the object dependencies on the F_GET_LOC function
Case 3—retrieve system grants on the ORADEV schema
Case 4—retrieve objects of function type in the ORADEV schema
Summary
Practice exercise
11. Profiling and Tracing PL/SQL Code
Tracing the PL/SQL programs
The DBMS_TRACE package
Installing DBMS_TRACE
DBMS_TRACE subprograms
The PLSQL_DEBUG parameter and the DEBUG option
Viewing the PL/SQL trace information
Demonstrating the PL/SQL tracing
Profiling the PL/SQL programs
Oracle hierarchical profiler—the DBMS_HPROF package
View profiler information
Demonstrating the profiling of a PL/SQL program
The plshprof utility
Sample reports
Summary
Practice exercise
12. Safeguarding PL/SQL Code against SQL Injection Attacks
SQL injection—an introduction
SQL injection—an overview
Types of SQL injection attacks
Preventing SQL injection attacks
Immunizing SQL injection attacks
Reducing the attack's surface
Controlling user privileges
Invoker's and definer's rights
Avoiding dynamic SQL
Bind arguments
Sanitizing inputs using DBMS_ASSERT
The DBMS_ASSERT package
Identifier formatting and verification process
DBMS_ASSERT—usage guidelines
DBMS_ASSERT—limitations
Testing the code for SQL injection flaws
Test strategy
Reviewing the code
Static code analysis
Fuzz tools
Generating test cases
Summary
Practice exercise
A. Answers to Practice Questions
Chapter 1, Overview of PL/SQL Programming Concepts
Chapter 2, Designing PL/SQL Code
Chapter 3, Using Collections
Chapter 4, Using Advanced Interface Methods
Chapter 5, Implementing VPD with Fine Grained Access Control
Chapter 6, Working with Large Objects
Chapter 7, Using SecureFile LOBs
Chapter 8, Compiling and Tuning to Improve Performance
Chapter 9, Caching to Improve Performance
Chapter 10, Analyzing PL/SQL Code
Chapter 11, Profiling and Tracing PL/SQL Code
Chapter 12, Safeguarding PL/SQL Code against SQL Injection Attacks
Index
Oracle Advanced PL/SQL Developer Professional Guide
Oracle Advanced PL/SQL Developer Professional Guide
Copyright © 2012 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: May 2012
Production Reference: 1070512
Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.
ISBN 978-1-84968-722-5
www.packtpub.com
Cover Image by Tina Negus (<tina_manthorpe@sky.com>)
Credits
Author
Saurabh K. Gupta
Reviewers
Kamran Agayev A.
Mohan Dutt
Marcel Hoefs
Ronald Rood
Acquisition Editor
Rukshana Khambatta
Lead Technical Editor
Pramila Balan
Technical Editors
Vrinda Amberkar
Prasad Dalvi
Project Coordinator
Alka Nayak
Proofreaders
Linda Morris
Kevin McGowan
Indexer
Rekha Nair
Graphics
Valentina D'Silva
Manu Joseph
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
Foreword
Many of us learned to use PL/SQL recently; many did this many years ago. At that time simple problems required simple PL/SQL code, with lots of procedural code in it. Isn't the procedural part what PL/SQL is all about? Yes, it is, but this is also a threat because, when it is not used smartly, the procedural looping might become a performance hog.
Pl/SQL has evolved a lot. Bulk collections should be commonly in use now. Many programmers that support multiple vendors have little or no knowledge about Oracle collections. Because of this they write code like we did during v7, leaving the huge performance benefits, that Oracle has, untouched.
For these programmers this book is a very helpful addition to their library of knowledge. It helps them to easily perform the same task, but maybe 70 times faster, without making the code more complex. Using the advanced techniques described in the book you can do that. Don't mix up advanced
with complex
. The fun about this is that many make their code complex using simple PL/SQL, trying to gain some performance, instead of effectively using advanced constructs in PL/SQL that in the end make the code easier to read and understand.
There is more to find in the book. Being a DBA, performance attracts a certain amount of attention. This is because performance is important. It greatly impacts the scalability of a database and the end user experience of the application. Other things you might find useful are the interfaces with the outside world, where external procedures can do work that does not fit the characteristics of a database.
Security is also something that attracts a DBA. Here you will find implementations of Virtual Private Database and enough remarks to keep the reader learning for quite a while. For example, how to protect against SQL injection? This again is a very interesting topic that should be taken very seriously. These days no network is safe. So scan every input.
I won't mention everything that is covered, just find a keyboard, your local database, and start reading. Try out the code samples and see where you can modify your existing code to take advantage of the new insights that the book will give you.
How advanced are the techniques described here depends on your mileage. For many the contents will be valuable enough to justify the term advanced
. As a reviewer it was a pleasure to read it and to try to push Saurabh Gupta to his limits. For me, I could use this book, even today.
Ronald Rood
Oracle ACE, Oracle DBA, OCM
PL/SQL is a programming language that is not only used by application developers, but also by database administrators in their daily tasks. This book contains information that every developer and even DBAs should know. As you read this book, you'll definitely learn a lot of new facts about PL/SQL programming. This book provides detailed information on general PL/SQL programming language, analyzing, tuning, tracing, and securing your code.
What I like most about the book is that it contains a lot of examples and helpful scripts for each chapter. This book also contains a lot of questions for the 1Z0-146 examination at the end of each chapter and it's one of the best guides for getting ready to pass the exam.
If you're a PL/SQL developer, whether a beginner or an expert, this book is for you.
Kamran Agayev A.
Oracle ACE, Oracle DBA Expert
About the Author
Saurabh K. Gupta got introduced to Oracle database around 5 years ago. Since then, he has been synchronizing his on job and off job interests with Oracle database programming. As an Oracle 11g Certified Advanced PL/SQL Professional, he soon moved from programming to database designing, development, and day-to-day database administration activities. He has been an active Oracle blogger and OTN forum member. He has authored and published more than 70 online articles and papers. His work can be seen in RMOUG journal, PSOUG, dbanotes, Exforsys, and Club Oracle. He shares his technical experience through his blog: http://sbhoracle.wordpress.com/. He is a member of All India Oracle Users Group (AIOUG) and loves to participate in technical meets and conferences.
Besides digging into Oracle, sketching and snooker are other pastimes for him. He can be reached through his blog SbhOracle for any comments, suggestions, or feedback regarding this book.
Acknowledgement
On a professional note, I am obliged to Ronald Rood, Kamran Agayev, Mohan Dutta, and Marcel Hoefs who reviewed the book with their own insights and perspectives. I was excited with the fact that the technical reviewers of my book are Oracle ACEs, highly respected, and recognized experts in the industry. I am grateful to Ronald who judged the worth of the book from the DBA perspective and helped me to extend my limits on the administrative aspect as well. Thanks to Kamran Agayev who consistently encouraged my writing styles and gave valuable inputs on the chapters. My obligations to Mohan Dutta and Marcel Hoefs who invested their valuable time in my work and added to the quality of the content. I would also like to express my gratitude for Arup Nanda, who has always been a great source of inspiration for me. His sessions and articles, covering all areas of Oracle database, have always been a great source of knowledge and motivation for me.
I would like to extend the appreciation to Packt Publishing for considering my proposal and accepting to go ahead on this book. My sincere thanks to Rukshana Khambatta, the Acquisition Editor at Packt for coordinating the kick-off activities of the book. I deeply appreciate the efforts of the Project Coordinator, Alka Nayak; the Lead Technical Editor, Pramila Balan; and the Technical Editors Vrinda Amberkar and Prasad Dalvi, whose diligent work and coordination added extra miles to the project. There was great tuning established between us and I am glad we worked parallely on the editorial process while abiding by the timelines.
It is correctly said that a man's personal and professional achievements are a showcase of his family's support and encouragement. I dedicate all my efforts and works to my parents, Suresh Chandra Gupta and Swadesh Gupta and family for their inevitable support, motivation, and sacrifices, and nurturing me towards all my achievements. Sincere thanks to my wife, Neha, and Sir J.B. Mall for their love, consistent support, and confidence in my endeavors and for being with me during my tough times.
About the Reviewers
Kamran Agayev A. is an Oracle ACE and Oracle Certified Professional DBA working at Azercell Telecom. He's an author of the book, Oracle Backup & Recovery: Expert secrets for using RMAN and Data Pump, and also shares his experience with a lot of step-by-step articles and video tutorials in his blog at http://kamranagayev.com. He also presents at Oracle OpenWorld, TROUG, and local events.
Mohan Dutt is an Oracle expert, having presented more than 55 sessions at Oracle conferences worldwide. An Oracle evangelist at large, he was awarded Member of the Year by Oracle Applications User Group (OAUG) in 2007. He authors the world's first blog dedicated entirely to Oracle certification. He has founded and chaired 3 Oracle Special Interest Groups (SIG). He was recognized as an Oracle ACE in 2011.
Marcel Hoefs learned his trade participating in numerous Oracle development projects, as an Oracle developer, since 1997. Being a specialist in SQL and PL/SQL database development, Oracle Forms, Reports, and Designer, Marcel currently works as a Technical Architect, Lead Developer, and Performance Specialist. With the advent of web technologies such as Web Services, ADF, and APEX, he currently specializes in innovative solutions opening up traditional Oracle database systems to the Web. As a senior Oracle Consultant with CIBER, he is also an Oracle competence leader, organizing and participating in knowledge sharing sessions with participants from within and outside CIBER.
Ronald Rood is an innovating Oracle DBA with over 20 years of IT experience. He has built and managed cluster databases on almost each and every platform that Oracle has ever supported, from the famous OPS databases in version 7, until the latest RAC releases, currently being 11g. Ronald is constantly looking for ways to get the most value out of the database to make the investment for his customers even more valuable. He knows how to handle the power of the rich Unix environment very well and this is what makes him a first class trouble-shooter and a true Oracle ACE. Next to the spoken languages such as Dutch, English, German, and French, he also writes fluently in many scripting languages.
Currently, Ronald is a principal consultant working for CIBER in The Netherlands where he cooperates in many complex projects for large companies where downtime is not an option. CIBER or CBR is a global full service IT provider and Oracle Platinum Partner.
Ronald often replies in the Oracle forums, writes his own blog (http://ronr.blogspot.com) called From errors we learn
and writes for various Oracle related magazines. He also wrote a book, Mastering Oracle Scheduler in Oracle 11g Databases, where he fills the gap between the Oracle documentation and customers' questions. You can find him on Twitter at http://twitter.com/ik_zelf.
Ronald has lots of certifications:
Oracle Certified Master
Oracle Certified Professional
Oracle Database 11g Tuning Specialist
Oracle Database 11g Data Warehouse Certified Implementation Specialist
Ronald fills his time with Oracle, his family, sky-diving, radio controlled model airplane flying, running a scouting group, and having a lot of fun.
He quotes, A problem is merely a challenge that might take a little time to be solved
.
www.PacktPub.com
Support files, eBooks, discount offers, and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Instant Updates on New Packt Books
Get notified! Find out when new books are published by following @PacktEnterprise on Twitter, or the Packt Enterprise Facebook page.
Preface
Oracle Database 11g brings in a weighted package of new features which takes the database management philosophy from instrumental to self-intelligence level. The new database features, which are more properly called advanced
, rather than complex
, aim either of the two purposes:
Replacement of a workaround solution with a permanent one (as an enhancement)
By virtue of routine researches and explorations, introduce a fresh feature to help database administrators and developers with their daily activities
Oracle Advanced PL/SQL Professional Guide focuses on advanced features of Oracle 11g PL/SQL. The areas targeted are PL/SQL code design, measuring and optimizing PL/SQL code performance, and analyzing PL/SQL code for reporting purposes and immunizing against attacks. The advanced programming topics such as usage of collections, implementation of VPD, interaction with external procedures in PL/SQL, performance orientation by caching results, tracing and profiling techniques, and protecting against SQL injection will familiarize you with the latest programming findings, trends and recommendations of Oracle. In addition, this book will help you to learn the latest, best practices of PL/SQL programming in terms of code writing, code analyzing for reporting purposes, tracing for performance, and safeguarding the PL/SQL code against hackers.
An investment in knowledge pays the best interest.
-Benjamin Franklin
The fact remains that the technical certifications from Oracle Corporation establish a benchmark of technical expertise and credibility, and set the tone of an improved career path for application developers. With the growing market in database development, Oracle introduced Advanced PL/SQL Professional Certification (1Z0-146) in the year 2008. The OCP (1Z0-146) certification exam tests aspirants on knowledge of advanced PL/SQL concepts (validated up to Oracle 11g Release 1). An advanced PL/SQL professional is expected to independently design, develop, and tune the PL/SQL code which can efficiently interface database systems and user applications.
The book, Oracle Advanced PL/SQL Professional Guide, is a sure recommendation for the preparation of the OCP certification (1Z0-146) exam. Advanced PL/SQL topics are explained thoroughly with the help of demonstrations, figures, and code examples. The book will not only explain a feature, but will also teach its implementation and application. You can easily pick up the content structure followed in the book. The code examples can be tried on your local database setups to give you a feel of the usage of a specific feature in real time scenarios.
What this book covers
Chapter 1, Overview of PL/SQL Programming Concepts, covers the overview of PL/SQL as the primary database programming language. It describes the characteristics of the language and its strengths in database development. This chapter speeds up with the structure of a PL/SQL block and reviews PL/SQL objects such as procedures, functions, and packages. In this chapter, we will also learn to work with SQL Developer.
Chapter 2, Designing PL/SQL Code, discusses the handling of cursors in a PL/SQL program. This chapter helps you to learn the guidelines for designing a cursor, usage of cursor variables, and cursor life cycle.
Chapter 3, Using Collections, introduces a very important feature of PL/SQL—collections. A collection in a database is very similar to arrays or maps in other programming languages. This chapter compares collection types and makes recommendations for the appropriate selection in a given situation. This chapter also covers the collection methods which are utility APIs for working with collections.
Chapter 4, Using Advanced Interface Methods, teaches how to interact with an external program written in a non-PL/SQL language, within PL/SQL. It demonstrates the execution steps for external procedures in PL/SQL. This steps describe the network configuration on a database server (mounted on Windows OS), library object creation, and publishing of a non-language program as an external routine.
Chapter 5, Implementing VPD with Fine Grained Access Control, introduces the concept of Fine Grained Access in PL/SQL. The working of FGAC as Virtual Private Database is explained in detail along with an insight into its key features. You will find stepwise implementation of VPD with the help of policy function and the DBMS_RLS package. This chapter also describes policy enforcement through application contexts.
Chapter 6, Working with Large Objects, discusses the traditional and conventional way of handling large objects in an Oracle database. This chapter starts with the familiarization of the available LOB data types (BLOB, CLOB, BFILE, and Temporary LOBs) and their significance. You will learn about the creation of LOB types in PL/SQL and their respective handling operations. This chapter demonstrates the management of LOB data types using SQL and the DBMS_LOB package.
Chapter 7, Using SecureFile LOBs, introduces one of the key innovations in Oracle 11g — SecureFiles. SecureFiles are upgraded LOBs which work on an improved philosophy of storage and maintenance. The key improvements of SecureFiles — deduplication, compression, and encryption — are licensed features. This chapter discusses and demonstrates the implementation of these three properties. You will learn how to migrate (or rather upgrade) the existing older LOBs into a new scheme — SecureFiles. The migration techniques covered use an online redefinition method and a partition method.
Chapter 8, Compiling and Tuning to Improve Performance, describes fair practices in effective PL/SQL programming. You will be very interested to discover how better code writing impacts code performance. This chapter explains an important aspect of query optimization — the PLSQL_OPTIMIZE_LEVEL parameter. The code behavior and optimization strategy at each level will help you to understand the language internals. Subsequently, the new PRAGMA feature will give you a deeper insight into subprogram inlining concepts.
Chapter 9, Caching to Improve Performance, covers another hot feature of Oracle 11g Database — server-side result caching. The newly introduced server-side cache component in SGA holds the results retrieved from SQL query or PL/SQL function. This chapter describes the configuration of a database server for caching feature through related parameters, implementation in SQL through RESULT_CACHE hint and implementation in PL/SQL function through the RESULT_CACHE clause. Besides the implementation section, this chapter teaches the validation and invalidation of result cache, using the DBMS_RESULT_CACHE package.
Chapter 10, Analyzing PL/SQL Code, helps you to understand and learn code diagnostics tricks and code analysis for reporting purposes. You will learn to monitor identifier usage, about compilation settings, and generate the subsequent reports from SQL Developer. This chapter discusses a very important addition in Oracle 11g — PL/Scope. It covers the explanations and illustrations to generate the structural reports through the dictionary views. In addition, this chapter also demonstrates the use of the DBMS_METADATA package to retrieve and extract metadata of database objects from the database in multiple formats.
Chapter 11, Profiling and Tracing PL/SQL Code, aims to demonstrate the tracing and profiling features in PL/SQL. The tracing demonstration uses the DBMS_TRACE package to trace the enabled or all calls in a PL/SQ program. The PL/SQL hierarchical profiler is a new innovation in 11g to identify and report the time consumed at each line of the program. The biggest benefit is that raw profiler data can be reproduced meaningfully into HTML reports.
Chapter 12, Safeguarding PL/SQL Code against SQL Injection Attacks, discusses the SQL injection as a concept and its remedies. The SQL injection is a serious attack on the vulnerable areas of the PL/SQL code which can lead to extraction of confidential information and many fatal results. You will learn the impacts and precautionary recommendations to avoid injective attacks. This chapter discusses the preventive measures such as using invoker's rights, client input validation tips, and using DBMS_ASSERT to sanitize inputs. It concludes on the testing strategies which can be practiced to identify vulnerable areas in SQL.
Appendix, Answers to Practice Questions, contains the answers to the practice questions for all chapters.
What you need for this book
You need to have a sound understanding