Oracle Advanced PL/SQL Developer Professional Guide

Book description

Master advanced PL/SQL concepts along with plenty of example questions for 1Z0-146 examination with this book and ebook.

  • Blitz the 1Z0-146 exam
  • Master the advanced features of PL/SQL to design and optimize code using real-time demonstrations
  • Efficiently design PL/SQL code with cursor design and subtypes

In Detail

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.

Table of contents

  1. Oracle Advanced PL/SQL Developer Professional Guide
    1. Table of Contents
    2. Oracle Advanced PL/SQL Developer Professional Guide
    3. Credits
    4. Foreword
    5. About the Author
    6. Acknowledgement
    7. About the Reviewers
    8. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
        3. Instant Updates on New Packt Books
    9. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    10. 1. Overview of PL/SQL Programming Concepts
      1. PL/SQL—the procedural aspect
        1. My first PL/SQL program
      2. PL/SQL development environments
        1. SQL Developer
          1. SQL Developer—the history
          2. Creating a connection
          3. SQL Worksheet
          4. Executing a SQL statement
          5. Calling a SQL script from SQL Developer
          6. Creating and executing an anonymous PL/SQL block
          7. Debugging the PL/SQL code
          8. Editing and saving the scripts
        2. SQL*Plus
          1. Executing a SQL statement in SQL*Plus
          2. Executing an anonymous PL/SQL block
      3. Procedures
        1. Executing a procedure
      4. Functions
        1. Function—execution methods
        2. Restrictions on calling functions from SQL expressions
      5. PL/SQL packages
      6. Cursors—an overview
        1. Cursor execution cycle
        2. Cursor attributes
        3. Cursor FOR loop
      7. Exception handling in PL/SQL
        1. System-defined exceptions
        2. User-defined exceptions
          1. The RAISE_APPLICATION_ERROR procedure
        3. Exception propagation
      8. Managing database dependencies
        1. Displaying the direct and indirect dependencies
        2. Dependency metadata
        3. Dependency issues and enhancements
      9. Reviewing Oracle-supplied packages
      10. Summary
      11. Practice exercise
    11. 2. Designing PL/SQL Code
      1. Understanding cursor structures
        1. Cursor execution cycle
        2. Cursor design considerations
        3. Cursor design—guidelines
        4. Cursor attributes
        5. Implicit cursors
        6. Explicit cursors
      2. Cursor variables
        1. Ref cursor types—strong and weak
          1. SYS_REFCURSOR
        2. Processing a cursor variable
        3. Cursor variables as arguments
        4. Cursor variables—restrictions
      3. Subtypes
        1. Subtype classification
          1. Oracle's predefined subtypes
          2. User-defined subtypes
        2. Type compatibility with subtypes
      4. Summary
      5. Practice exercise
    12. 3. Using Collections
      1. Collections—an overview
        1. Categorization
        2. Selecting an appropriate collection type
      2. Associative arrays
      3. Nested tables
        1. Nested table collection type as the database object
          1. DML operations on nested table columns
            1. Inserting a nested table instance
            2. Selecting a nested table column
            3. Updating the nested table instance
          2. A nested table collection type in PL/SQL
        2. Additional features of a nested table
      4. Varray
        1. Varray in PL/SQL
        2. Varray as a database collection type
          1. DML operations on varray type columns
            1. Inserting a varray collection type instance
            2. Selecting a varray column
            3. Updating the varray instance
      5. Collections—a comparative study
        1. Common characteristics of collection types
        2. Nested table versus associative arrays
        3. Nested table versus varrays
      6. PL/SQL collection methods
        1. EXISTS
        2. COUNT
        3. LIMIT
        4. FIRST and LAST
        5. PRIOR and NEXT
        6. EXTEND
        7. TRIM
        8. DELETE
      7. Manipulating collection elements
      8. Collection initialization
      9. Summary
      10. Practice exercise
    13. 4. Using Advanced Interface Methods
      1. Understanding external routines
        1. Architecture of external routines
        2. Oracle Net Configuration
          1. TNSNAMES.ora
          2. LISTENER.ora
          3. Oracle Net Configuration verification
        3. Benefits of external procedures
      2. Executing external C programs from PL/SQL
        1. Executing C program through external procedure—development steps
      3. Executing Java programs from PL/SQL
        1. Calling a Java class method from PL/SQL
        2. Uploading a Java class into the database—development steps
        3. The loadjava utility—an illustration
        4. Creating packages for Java class methods
      4. Summary
      5. Practice exercise
    14. 5. Implementing VPD with Fine Grained Access Control
      1. Fine Grained Access Control
        1. Overview
        2. Virtual Private Database—the alias
        3. How FGAC or VPD works?
          1. Salient features of VPD
      2. VPD implementation—outline and components
        1. Application context
        2. Policy function definition and implementation of row-level security
        3. Associating a policy using the DBMS_RLS package
      3. VPD implementation—demonstrations
        1. Assignment 1—implementing VPD using simple security policy
        2. Assignment 2—implementing VPD using an application context
      4. VPD policy metadata
      5. Policy utilities—refresh and drop
      6. Summary
      7. Practice exercise
    15. 6. Working with Large Objects
      1. Introduction to the LOB data types
        1. Internal LOB
        2. External LOB
      2. Understanding the LOB data types
        1. LOB value and LOB locators
        2. BLOB or CLOB!
        3. BFILE
        4. Temporary LOBs
      3. Creating LOB data types
        1. Directories
        2. Creating LOB data type columns in a table
      4. Managing LOB data types
        1. Managing internal LOBs
        2. Securing and managing BFILEs
        3. The DBMS_LOB package—overview
          1. Security model
          2. DBMS_LOB constants
          3. DBMS_LOB data types
          4. DBMS_LOB subprograms
          5. Rules and regulations
            1. Internal LOBs
            2. BFILEs
      5. Working with the CLOB, BLOB, and BFILE data types
        1. Initializing LOB data type columns
        2. Inserting data into a LOB column
        3. Populating a LOB data type using an external file
        4. Selecting LOB data
        5. Modifying the LOB data
        6. Delete LOB data
        7. Miscellaneous LOB notes
          1. LOB column states
          2. Locking a row containing LOB
          3. Opening and closing LOBs
          4. Accessing LOBs
          5. LOB restrictions
      6. Migrating from LONG to LOB
      7. Using temporary LOBs
        1. Temporary LOB operations
        2. Managing temporary LOBs
        3. Validating, creating, and freeing a temporary LOB
      8. Summary
      9. Practice exercise
    16. 7. Using SecureFile LOBs
      1. Introduction to SecureFiles
        1. SecureFile LOB—an overview
          1. Architectural enhancements in SecureFiles
        2. SecureFile LOB features
      2. Working with SecureFiles
        1. SecureFile metadata
        2. Enabling advanced features in SecureFiles
          1. Deduplication
          2. Compression
          3. Encryption
      3. Migration from BasicFiles to SecureFiles
        1. Online Reefinition method
      4. Summary
      5. Practice exercise
    17. 8. Compiling and Tuning to Improve Performance
      1. Native and interpreted compilation techniques
        1. Real native compilation
        2. Selecting the appropriate compilation mode
          1. When to choose interpreted compilation mode?
          2. When to choose native compilation mode?
        3. Setting the compilation mode
        4. Querying the compilation settings
        5. Compiling a program unit for a native or interpreted compilation
        6. Compiling the database for PL/SQL native compilation (NCOMP)
      2. Tuning PL/SQL code
        1. Comparing SQL and PL/SQL
        2. Avoiding implicit data type conversion
        3. Understanding the NOT NULL constraint
        4. Using the PLS_INTEGER data type for arithmetic operations
        5. Using a SIMPLE_INTEGER data type
        6. Modularizing the PL/SQL code
        7. Using bulk binding
          1. Using SAVE_EXCEPTIONS
        8. Rephrasing the conditional control statements
          1. Conditions with an OR logical operator
          2. Conditions with an AND logical operator
      3. Enabling intra unit inlining
        1. PLSQL_OPTIMIZE_LEVEL—the Oracle initialization parameter
          1. Case 1—PLSQL_OPTIMIZE_LEVEL = 0
          2. Case 2—PLSQL_OPTIMIZE_LEVEL = 1
          3. Case 3—PLSQL_OPTIMIZE_LEVEL = 2
          4. Case 4—PLSQL_OPTIMIZE_LEVEL = 3
      4. PRAGMA INLINE
      5. Summary
      6. Practice exercise
    18. 9. Caching to Improve Performance
      1. Introduction to result cache
        1. Server-side result cache
          1. SQL query result cache
          2. PL/SQL function result cache
        2. OCI client results cache
      2. Configuring the database for the server result cache
        1. The DBMS_RESULT_CACHE package
      3. Implementing the result cache in SQL
        1. Manual result cache
        2. Automatic result cache
        3. Result cache metadata
          1. Query result cache dependencies
          2. Cache memory statistics
        4. Invalidation of SQL result cache
        5. Displaying the result cache memory report
        6. Read consistency of the SQL result cache
        7. Limitation of SQL result cache
      4. Implementing result cache in PL/SQL
        1. The RESULT_CACHE clause
        2. Cross-session availability of cached results
        3. Invalidation of PL/SQL result cache
        4. Limitations of PL/SQL function result cache
          1. Argument and return type restrictions
          2. Function structural restrictions
      5. Summary
      6. Practice exercise
    19. 10. Analyzing PL/SQL Code
      1. Track coding information
        1. [DBA | ALL | USER]_ARGUMENTS
        2. [DBA | ALL | USER]_OBJECTS
        3. [DBA | ALL | USER]_SOURCE
        4. [DBA | ALL | USER]_PROCEDURES
        5. [DBA | ALL | USER]_DEPENDENCIES
      2. Using SQL Developer to find coding information
        1. The DBMS_DESCRIBE package
        2. DBMS_UTILITY.FORMAT_CALL_STACK
        3. Tracking propagating exceptions in PL/SQL code
      3. Determining identifier types and usages
        1. The PL/Scope tool
          1. The PL/Scope identifier collection
          2. The PL/Scope report
          3. Illustration
          4. Applications of the PL/Scope report
      4. The DBMS_METADATA package
        1. DBMS_METADATA data types and subprograms
        2. Parameter requirements
        3. The DBMS_METADATA transformation parameters and filters
        4. Working with DBMS_METADATA—illustrations
          1. Case 1—retrieve the metadata of a single object
          2. Case 2—retrieve the object dependencies on the F_GET_LOC function
          3. Case 3—retrieve system grants on the ORADEV schema
          4. Case 4—retrieve objects of function type in the ORADEV schema
      5. Summary
      6. Practice exercise
    20. 11. Profiling and Tracing PL/SQL Code
      1. Tracing the PL/SQL programs
        1. The DBMS_TRACE package
          1. Installing DBMS_TRACE
          2. DBMS_TRACE subprograms
        2. The PLSQL_DEBUG parameter and the DEBUG option
        3. Viewing the PL/SQL trace information
        4. Demonstrating the PL/SQL tracing
      2. Profiling the PL/SQL programs
        1. Oracle hierarchical profiler—the DBMS_HPROF package
          1. View profiler information
          2. Demonstrating the profiling of a PL/SQL program
        2. The plshprof utility
          1. Sample reports
      3. Summary
      4. Practice exercise
    21. 12. Safeguarding PL/SQL Code against SQL Injection Attacks
      1. SQL injection—an introduction
        1. SQL injection—an overview
        2. Types of SQL injection attacks
        3. Preventing SQL injection attacks
      2. Immunizing SQL injection attacks
        1. Reducing the attack's surface
          1. Controlling user privileges
          2. Invoker's and definer's rights
        2. Avoiding dynamic SQL
        3. Bind arguments
        4. Sanitizing inputs using DBMS_ASSERT
          1. The DBMS_ASSERT package
            1. Identifier formatting and verification process
            2. DBMS_ASSERT—usage guidelines
            3. DBMS_ASSERT—limitations
      3. Testing the code for SQL injection flaws
        1. Test strategy
        2. Reviewing the code
        3. Static code analysis
        4. Fuzz tools
        5. Generating test cases
      4. Summary
      5. Practice exercise
    22. A. Answers to Practice Questions
      1. Chapter 1, Overview of PL/SQL Programming Concepts
      2. Chapter 2, Designing PL/SQL Code
      3. Chapter 3, Using Collections
      4. Chapter 4, Using Advanced Interface Methods
      5. Chapter 5, Implementing VPD with Fine Grained Access Control
      6. Chapter 6, Working with Large Objects
      7. Chapter 7, Using SecureFile LOBs
      8. Chapter 8, Compiling and Tuning to Improve Performance
      9. Chapter 9, Caching to Improve Performance
      10. Chapter 10, Analyzing PL/SQL Code
      11. Chapter 11, Profiling and Tracing PL/SQL Code
      12. Chapter 12, Safeguarding PL/SQL Code against SQL Injection Attacks
    23. Index

Product information

  • Title: Oracle Advanced PL/SQL Developer Professional Guide
  • Author(s): Saurabh Gupta
  • Release date: May 2012
  • Publisher(s): Packt Publishing
  • ISBN: 9781849687225