12c dev guide.pdf

Upload: rav1234

Post on 05-Feb-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/21/2019 12c dev guide.pdf

    1/708

    Oracle DatabaseDevelopment Guide

    12cRelease 1 (12.1)

    E17620-15

    January 2014

  • 7/21/2019 12c dev guide.pdf

    2/708

    Oracle Database Development Guide, 12cRelease 1 (12.1)

    E17620-15

    Copyright 1996, 2014, Oracle and/or its affiliates. All rights reserved.

    Primary Authors: Chuck Murray, Tom Kyte

    Contributing Authors: D. Adams, L. Ashdown, M. Cowan, P. Huey, J. Melnick, S. Moore, R. Moran, E.Paapanen, J. Russell, R. Strohm, R. Ward

    Contributor: The Oracle Database 12cdocumentation is dedicated to Mark Townsend, who was aninspiration to all who worked on this release.

    Contributors: D. Alpern, G. Arora, C. Barclay, D. Bronnikov, T. Chang, L. Chen, B. Cheng, M. Davidson, R.Day, R. Decker, G. Doherty, D. Elson, A. Ganesh, M. Hartstein, Y. Hu, J. Huang, C. Iyer, N. Jain, R. Jenkins

    Jr., S. Kotsovolos, V. Krishnaswamy, R. Kumar, S. Kumar, C. Lei, B. Llewellyn, D. Lorentz, K. Mohan, V.Moore, K. Muthukkaruppan, V. Moore, J. Muller, R. Murthy, R. Pang, B. Sinha, S. Vemuri, W. Wang, D.Wong, A. Yalamanchi, Q. Yu

    This software and related documentation are provided under a license agreement containing restrictions onuse and disclosure and are protected by intellectual property laws. Except as expressly permitted in yourlicense agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license,transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverseengineering, disassembly, or decompilation of this software, unless required by law for interoperability, isprohibited.

    The information contained herein is subject to change without notice and is not warranted to be error-free. If

    you find any errors, please report them to us in writing.

    If this is software or related documentation that is delivered to the U.S. Government or anyone licensing iton behalf of the U.S. Government, the following notice is applicable:

    U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software,any programs installed on the hardware, and/or documentation, delivered to U.S. Government end usersare "commercial computer software" pursuant to the applicable Federal Acquisition Regulation andagency-specific supplemental regulations. As such, use, duplication, disclosure, modification, andadaptation of the programs, including any operating system, integrated software, any programs installed onthe hardware, and/or documentation, shall be subject to license terms and license restrictions applicable tothe programs. No other rights are granted to the U.S. Government.

    This software or hardware is developed for general use in a variety of information managementapplications. It is not developed or intended for use in any inherently dangerous applications, includingapplications that may create a risk of personal injury. If you use this software or hardware in dangerousapplications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and othermeasures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damagescaused by use of this software or hardware in dangerous applications.

    Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks oftheir respective owners.

    Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarksare used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD,Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of AdvancedMicro Devices. UNIX is a registered trademark of The Open Group.

    This software or hardware and documentation may provide access to or information on content, products,and services from third parties. Oracle Corporation and its affiliates are not responsible for and expresslydisclaim all warranties of any kind with respect to third-party content, products, and services. OracleCorporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to youraccess to or use of third-party content, products, or services.

  • 7/21/2019 12c dev guide.pdf

    3/708

    iii

    Contents

    Preface ............................................................................................................................................................. xxxi

    Audience................................................................................................................................................... xxxi

    Documentation Accessibility................................................................................................................. xxxi

    Related Documents ............... .............. ................ .............. ............... .............. ............... .............. ........... xxxii

    Conventions ............................................................................................................................................ xxxii

    Changes in This Release for Oracle Database Development Guide....................... xxxv

    Changes in Oracle Database 12cRelease 1 (12.1.0.1)........................................................................ xxxv

    Part I Database Development Fundamentals

    1 Design Basics

    1.1 Design for Performance ............................................................................................................. 1-1

    1.2 Design for Scalability.................................................................................................................. 1-2

    1.3 Design for Extensibility.............................................................................................................. 1-2

    1.3.1 Data Cartridges .............. ................ .............. ............... .............. ............... .............. .............. 1-21.3.2 External Procedures............................................................................................................. 1-3

    1.3.3 User-Defined Functions and Aggregate Functions .............. ............... ................ ........... 1-3

    1.3.4 Object-Relational Features.................................................................................................. 1-3

    1.4 Design for Security ..................................................................................................................... 1-4

    1.5 Design for Availability............................................................................................................... 1-4

    1.6 Design for Portability .............. ............... ............... ............... .............. ................ .............. .......... 1-4

    1.7 Design for Diagnosability.......................................................................................................... 1-5

    1.8 Design for Special Environments ............... ............... ............... ................ ............... ............... .. 1-5

    1.8.1 Data Warehousing .............. .............. ............... .............. ................ .............. ............... ......... 1-5

    1.8.2 Online Transaction Processing (OLTP) ................ ............... .............. ................ ............... 1-6

    1.9 Features for Special Scenarios .............. ................ .............. ............... .............. ............... ........... 1-71.9.1 SQL Analytic Functions ................ .............. ............... ............... .............. ................ ............ 1-7

    1.9.2 Materialized Views.............................................................................................................. 1-8

    1.9.3 Partitioning ............. ................ .............. ............... .............. ............... ............... ............... ...... 1-9

    1.9.4 Temporal Validity Support ............................................................................................. 1-10

    2 Performance and Scalability

    2.1 Performance Strategies............................................................................................................... 2-1

  • 7/21/2019 12c dev guide.pdf

    4/708

    iv

    2.1.1 Designing Your Data Model to Perform .............. ............... ............... .............. ................ 2-1

    2.1.1.1 Analyze Requirements................................................................................................. 2-2

    2.1.1.2 Create the Database Design ............... .............. ................ .............. ............... .............. 2-2

    2.1.1.3 Implement the Database Application........................................................................ 2-3

    2.1.1.4 Maintain the Database and Database Application ............... ............... .............. ...... 2-4

    2.1.2 Setting Performance Goals - Metrics................................................................................. 2-5

    2.1.3 Benchmarking Your Application....................................................................................... 2-52.2 Tools for Performance ............. ............... ............... ............... ............... .............. ................ ......... 2-6

    2.2.1 About Tools for Performance............................................................................................. 2-6

    2.2.1.1 Using DBMS_APPLICATION_INFO ....................................................................... 2-6

    2.2.1.2 Using SQL Trace Facility (SQL_TRACE) in Your Application.............................. 2-6

    2.2.1.3 Using the EXPLAIN PLAN......................................................................................... 2-7

    2.3 Monitoring Database Performance .............. .............. ............... ............... ............... ............... .. 2-8

    2.3.1 About Monitoring Database Performance....................................................................... 2-8

    2.4 Using Instrumentation ............................................................................................................ 2-10

    2.4.1 About Instrumentation .................................................................................................... 2-10

    2.5 Testing for Performance.......................................................................................................... 2-10

    2.5.1 About Testing for Performance ...................................................................................... 2-102.6 Using Bind Variables ............................................................................................................... 2-12

    2.7 Using Client Result Cache ...................................................................................................... 2-13

    2.7.1 About Client Result Cache .............................................................................................. 2-13

    2.7.2 Benefits of Client Result Cache....................................................................................... 2-14

    2.7.3 Guidelines for Using Client Result Cache..................................................................... 2-15

    2.7.3.1 SQL Hints.................................................................................................................... 2-16

    2.7.3.2 Table Annotation ....................................................................................................... 2-16

    2.7.3.3 Checking Table Annotation Mode.......................................................................... 2-17

    2.7.3.4 Session Parameters .................................................................................................... 2-17

    2.7.3.5 Effective Result Cache Table Mode............ .............. ................ .............. ............... .. 2-18

    2.7.3.6 Cache Example Use Cases........................................................................................ 2-18

    2.7.3.7 Queries That Are Not Cached ................................................................................. 2-19

    2.7.4 Client Cache Consistency ................................................................................................ 2-19

    2.7.5 Deployment Time Settings for Client Result Cache .................................................... 2-20

    2.7.5.1 Client Configuration File.......................................................................................... 2-21

    2.7.6 Client Cache Statistics ...................................................................................................... 2-21

    2.7.7 Validation of the Client Result Cache............................................................................ 2-22

    2.7.7.1 Timing Measurement................................................................................................ 2-22

    2.7.7.2 Using v$mystat .......................................................................................................... 2-22

    2.7.7.3 Using v$sqlarea.......................................................................................................... 2-22

    2.7.8 Client-Side Result Cache and Server Result Cache ..................................................... 2-23

    2.7.9 Client Result Cache Demo Files...................................................................................... 2-23

    2.7.10 Compatibility with Previous Releases........................................................................... 2-23

    2.7.11 Where To Find More Information About Client Result Cache.................................. 2-24

    2.8 Statement Caching ................................................................................................................... 2-24

    2.9 OCI Client Statement Cache Auto-Tuning........................ .............. ............... ............... ....... 2-25

    2.10 Client-Side Deployment Parameters..................................................................................... 2-25

    2.11 Using Query Change Notification......................................................................................... 2-26

    2.12 Using Database Resident Connection Pooling (DRCP) .............. .............. ............... .......... 2-26

  • 7/21/2019 12c dev guide.pdf

    5/708

    v

    2.12.1 About Database Resident Connection Pooling ............................................................ 2-27

    2.12.2 Configuring Database Resident Connection Pooling............. ............... ............... ....... 2-28

    2.12.3 Using JDBC with DRCP................................................................................................... 2-28

    2.12.4 Using OCI Session Pool APIs with DRCP....................... ............... ............... ............... . 2-29

    2.12.5 Session Purity and Connection Class......... .............. ................ .............. ............... ......... 2-30

    2.12.5.1 Session Purity............................................................................................................. 2-30

    2.12.5.2 Connection Class ....................................................................................................... 2-312.12.5.3 Defaults for Session Purity and Connection Class ............................................... 2-31

    2.12.6 Starting the Database Resident Connection Pool.................. .............. ................ ......... 2-32

    2.12.7 Enabling Database Resident Connection Pooling................. .............. .............. ........... 2-32

    2.12.8 Benefiting from the Scalability of DRCP in an OCI Application.............. ................ . 2-32

    2.12.9 Benefiting from the Scalability of DRCP in a Java Application .............. ............... .... 2-33

    2.12.10 Best Practices for Using DRCP........................................................................................ 2-33

    2.12.11 Compatibility and Migration .......................................................................................... 2-34

    2.12.12 Restrictions on Using Database Resident Connection Pooling............... ............... .... 2-34

    2.12.13 Using DRCP with Custom Pools.................................................................................... 2-35

    2.12.14 Marking Sessions Explicitly as Stateful or Stateless .................................................... 2-36

    2.12.15 DRCP with Real Application Clusters ............................ ............... .............. ................ . 2-372.12.16 DRCP with Pluggable Databases .......... ............... ............... .............. ................ ............ 2-37

    2.12.17 DRCP with Data Guard ..................... ............... ............... ............... .............. ............... ... 2-37

    2.13 Using Runtime Connection Load Balancing................ ................ ............... ............... .......... 2-37

    2.13.1 About Runtime Connection Load Balancing................................................................ 2-37

    2.13.2 Enabling and Disabling Runtime Connection Load Balancing ................................. 2-38

    2.13.3 Receiving Load Balancing Advisory FAN Events....................................................... 2-39

    3 Security

    3.1 Enabling User Access with Grants, Roles, and Least Privilege............................................ 3-1

    3.2 Automating Database Logins.................................................................................................... 3-23.3 Controlling User Access with Fine-Grained Access Control................................................ 3-3

    3.4 Using Invoker's and Definer's Rights for Procedures and Functions ............. ................ .... 3-4

    3.4.1 What Are Invoker's Rights and Definer's Rights? ............... ............... ............... ............. 3-4

    3.4.2 Protecting Users Who Run Invoker's Rights Procedures and Functions ................ .... 3-5

    3.4.3 How Default Rights Are Handled for Java Stored Procedures ............... .............. ....... 3-5

    3.5 Managing External Procedures for Your Applications .............. ............... ................ ............ 3-6

    3.6 Auditing User Activity............................................................................................................... 3-6

    4 High Availability

    4.1 Failover and Query Replay........................................................................................................ 4-1

    4.1.1 Transparent Application Failover (TAF).......................................................................... 4-14.1.1.1 About Transparent Application Failover.................................................................. 4-1

    4.1.1.2 Configuring Transparent Application Failover ............... ............... ............... .......... 4-2

    4.1.1.3 Using Transparent Application Failover Callbacks .............. ................ ................ .. 4-2

    4.1.2 Application Continuity....................................................................................................... 4-3

    4.2 Fast Application Notification (FAN) and Fast Connection Failover (FCF)........................ 4-3

    4.2.1 About Fast Application Notification (FAN) ............... ............... .............. ............... ........ 4-3

    4.2.2 About Fast Connection Failover (FCF)............................................................................. 4-4

  • 7/21/2019 12c dev guide.pdf

    6/708

    vi

    4.3 Application Continuity and Transaction Guard ............... ................ .............. ............... ........ 4-5

    4.3.1 Transaction Guard............................................................................................................... 4-6

    4.3.2 Application Continuity for Java .............. ............... ................ .............. ............... .............. 4-6

    4.4 Service and Load Management for Database Clouds............................................................ 4-7

    4.4.1 About Service and Load Management for Database Clouds.............. ............... ........... 4-7

    5 Advanced PL/SQL Features

    5.1 PL/SQL Data Types ................................................................................................................... 5-1

    5.2 Dynamic SQL............................................................................................................................... 5-1

    5.3 PL/SQL Optimize Level ............. ................ .............. ............... .............. ............... ............... ...... 5-1

    5.4 Compiling PL/SQL Units for Native Execution ............. ............... ............... .............. ........... 5-2

    5.5 Exception Handling.................................................................................................................... 5-2

    5.6 Conditional Compilation ................ .............. ............... ............... .............. ................ ............... .. 5-2

    5.7 Bulk Binding ............. .............. ................ .............. ............... .............. ................ ............... ........... 5-2

    Part II SQL for Application Developers

    6 SQL Processing for Application Developers

    6.1 Description of SQL Statement Processing............................................................................... 6-1

    6.1.1 Stages of SQL Statement Processing ............... ............... ............... .............. ................ ...... 6-2

    6.1.2 Shared SQL Areas................................................................................................................ 6-3

    6.2 Grouping Operations into Transactions.................................................................................. 6-4

    6.2.1 Deciding How to Group Operations in Transactions ............... ............... ............... ....... 6-4

    6.2.2 Improving Transaction Performance................................................................................ 6-4

    6.2.3 Managing Commit Redo Action........................................................................................ 6-5

    6.2.4 Determining Transaction Outcome After a Recoverable Outage................................. 6-7

    6.2.4.1 Understanding Transaction Guard............................................................................ 6-7

    6.2.4.2 Understanding DBMS_APP_CONT.GET_LTXID_OUTCOME ............... ............. 6-9

    6.2.4.3 Using Transaction Guard ......................................................................................... 6-11

    6.3 Ensuring Repeatable Reads with Read-Only Transactions ............................................... 6-11

    6.4 Locking Tables Explicitly........................................................................................................ 6-12

    6.4.1 Privileges Required to Acquire Table Locks................................................................. 6-13

    6.4.2 Choosing a Locking Strategy .......................................................................................... 6-13

    6.4.2.1 When to Lock with ROW SHARE MODE and ROW EXCLUSIVE MODE...... 6-14

    6.4.2.2 When to Lock with SHARE MODE ........................................................................ 6-14

    6.4.2.3 When to Lock with SHARE ROW EXCLUSIVE MODE...................................... 6-15

    6.4.2.4 When to Lock with EXCLUSIVE MODE ............................................................... 6-16

    6.4.3 Letting Oracle Database Control Table Locking .......................................................... 6-16

    6.4.4 Explicitly Acquiring Row Locks..................................................................................... 6-16

    6.4.5 Examples of Concurrency Under Explicit Locking ..................................................... 6-17

    6.5 Using Oracle Lock Management Services (User Locks)...................... .............. ............... .. 6-23

    6.5.1 When to Use User Locks.................................................................................................. 6-24

    6.5.2 Viewing and Monitoring Locks...................................................................................... 6-25

    6.6 Using Serializable Transactions for Concurrency Control ................................................ 6-25

    6.6.1 Transaction Interaction and Isolation Level ................................................................. 6-26

    6.6.2 Setting Isolation Levels .................................................................................................... 6-27

  • 7/21/2019 12c dev guide.pdf

    7/708

    vii

    6.6.3 Serializable Transactions and Referential Integrity..................................................... 6-28

    6.6.4 READ COMMITTED and SERIALIZABLE Isolation Levels ..................................... 6-29

    6.6.4.1 Transaction Set Consistency Differences ............................................................... 6-30

    6.6.4.2 Choosing Transaction Isolation Levels........... .............. ................ ............... ........... 6-30

    6.7 Autonomous Transactions...................................................................................................... 6-31

    6.7.1 Examples of Autonomous Transactions.................... ............... ............... ............... ....... 6-33

    6.7.1.1 Ordering a Product.................................................................................................... 6-346.7.1.2 Withdrawing Money from a Bank Account .......................................................... 6-34

    6.7.2 Declaring Autonomous Routines ................................................................................... 6-37

    6.8 Resuming Execution After Storage Allocation Errors .............. ................ ............... ........... 6-38

    6.8.1 What Operations Have Resumable Storage Allocation? ............................................ 6-38

    6.8.2 Handling Suspended Storage Allocation...................................................................... 6-38

    6.8.2.1 Using an AFTER SUSPEND Trigger in the Application.................... .............. .... 6-39

    6.8.2.2 Checking for Suspended Statements ...................................................................... 6-40

    7 Using SQL Data Types in Database Applications

    7.1 Using the Correct and Most Specific Data Type .............. ................ ............... ................ ....... 7-1

    7.1.1 How the Correct Data Type Increases Data Integrity ............... ................ ............... ...... 7-2

    7.1.2 How the Most Specific Data Type Decreases Storage Requirements .............. ............ 7-2

    7.1.3 How the Correct Data Type Improves Performance...................................................... 7-2

    7.2 Representing Character Data .............. .............. ............... ............... .............. ................ ............ 7-5

    7.3 Representing Numeric Data...................................................................................................... 7-6

    7.3.1 Floating-Point Number Components .............. ................ ............... .............. ................ .... 7-7

    7.3.2 Floating-Point Number Formats ....................................................................................... 7-8

    7.3.2.1 Binary Floating-Point Formats ................................................................................... 7-8

    7.3.3 Representing Special Values with Native Floating-Point Data Types......................... 7-9

    7.3.4 Comparing Native Floating-Point Values.................... ............... .............. .............. ...... 7-10

    7.3.5 Arithmetic Operations with Native Floating-Point Data Types............... ................ . 7-107.3.6 Conversion Functions for Native Floating-Point Data Types............. .............. ......... 7-11

    7.3.7 Client Interfaces for Native Floating-Point Data Types............... ............... ............... . 7-11

    7.4 Representing Date and Time Data ........................................................................................ 7-12

    7.4.1 Displaying Current Date and Time................................................................................ 7-13

    7.4.2 Inserting and Displaying Dates ...................................................................................... 7-14

    7.4.3 Inserting and Displaying Times ..................................................................................... 7-15

    7.4.4 Arithmetic Operations with Datetime Data Types...................................................... 7-16

    7.4.5 Conversion Functions for Datetime Data Types .......................................................... 7-16

    7.4.6 Importing, Exporting, and Comparing Datetime Types.......... ............... ............... ..... 7-17

    7.5 Representing Specialized Data............ .............. ............... ................ ............. ................ ......... 7-17

    7.5.1 Representing Spatial Data ............................................................................................... 7-187.5.2 Representing Multimedia Data............. .............. ............... ............... ............... ............... 7-18

    7.5.3 Representing Large Amounts of Data ........................................................................... 7-18

    7.5.3.1 Large Objects (LOBs)................................................................................................. 7-18

    7.5.3.2 LONG and LONG RAW Data Types ..................................................................... 7-19

    7.5.4 Representing Searchable Text ......................................................................................... 7-19

    7.5.5 Representing XML Data................ .............. ............... .............. ............... .............. ........... 7-19

    7.5.6 Representing Dynamically Typed Data ........................................................................ 7-20

    7.5.7 Representing ANSI, DB2, and SQL/DS Data............................................................... 7-21

  • 7/21/2019 12c dev guide.pdf

    8/708

    viii

    7.6 Identifying Rows by Address ................................................................................................ 7-22

    7.7 Displaying Metadata for SQL Operators and Functions ................................................... 7-23

    7.7.1 ARGn Data Type............................................................................................................... 7-24

    7.7.2 DISP_TYPE Data Type..................................................................................................... 7-24

    7.7.3 SQL Data Type Families .................................................................................................. 7-24

    8 Using Regular Expressions in Database Applications

    8.1 Overview of Regular Expressions ............... ............... .............. ............... ............... ............... ... 8-1

    8.2 Oracle SQL Support for Regular Expressions......................................................................... 8-2

    8.3 Oracle SQL and POSIX Regular Expression Standard ............... ............... ............... ............. 8-4

    8.4 Operators in Oracle SQL Regular Expressions....................................................................... 8-4

    8.4.1 POSIX Operators in Oracle SQL Regular Expressions................................................... 8-4

    8.4.2 Oracle SQL Multilingual Extensions to POSIX Standard ............... ............... ................ 8-7

    8.4.3 Oracle SQL PERL-Influenced Extensions to POSIX Standard .............. ............... ......... 8-7

    8.5 Using Regular Expressions in SQL Statements: Scenarios ............... ................ .............. ...... 8-9

    8.5.1 Using a Constraint to Enforce a Phone Number Format............................................... 8-9

    8.5.2 Using Back References to Reposition Characters......................................................... 8-10

    9 Using Indexes in Database Applications

    9.1 Guidelines for Managing Indexes ............. ............... .............. ................ .............. ............... ..... 9-1

    9.2 Managing Indexes....................................................................................................................... 9-2

    9.3 When to Use Domain Indexes................................................................................................... 9-2

    9.4 When to Use Function-Based Indexes .............. .............. ............... .............. ................ ............ 9-2

    9.4.1 Advantages of Function-Based Indexes ............... ............... ............... .............. ................ 9-3

    9.4.2 Disadvantages of Function-Based Indexes ................ .............. ............... .............. ........... 9-4

    9.4.3 Examples of Function-Based Indexes .............. ............... ................ .............. ............... ..... 9-5

    10 Maintaining Data Integrity in Database Applications

    10.1 Enforcing Business Rules with Constraints ......................................................................... 10-2

    10.2 Enforcing Business Rules with Both Constraints and Application Code.............. .......... 10-3

    10.3 Creating Indexes for Use with Constraints .......................................................................... 10-4

    10.4 When to Use NOT NULL Constraints.................................................................................. 10-4

    10.5 When to Use Default Column Values................................................................................... 10-6

    10.6 Choosing a Primary Key for a Table (PRIMARY KEY Constraint) .................................. 10-6

    10.7 When to Use UNIQUE Constraints....................................................................................... 10-7

    10.8 Enforcing Referential Integrity with FOREIGN KEY Constraints.................. ............... ... 10-8

    10.8.1 FOREIGN KEY Constraints and NULL Values ......................................................... 10-10

    10.8.2Defining Relationships Between Parent and Child Tables........................ ...............

    10-10

    10.8.3 Rules for Multiple FOREIGN KEY Constraints ............. ............... .............. .............. 10-11

    10.8.4 Deferring Constraint Checks....................... .............. ............... ................ .............. ....... 10-11

    10.9 Minimizing Space and Time Overhead for Indexes Associated with Constraints ...... 10-13

    10.10 Guidelines for Indexing Foreign Keys................................................................................ 10-13

    10.11 Referential Integrity in a Distributed Database................... ............... ................ ............... 10-13

    10.12 When to Use CHECK Constraints....................................................................................... 10-14

    10.12.1 Restrictions on CHECK Constraints .................. ............... .............. ............... ............. 10-14

    10.12.2 Designing CHECK Constraints .................................................................................... 10-15

  • 7/21/2019 12c dev guide.pdf

    9/708

    ix

    10.12.3 Rules for Multiple CHECK Constraints ...................................................................... 10-15

    10.12.4 Choosing Between CHECK and NOT NULL Constraints ....................................... 10-15

    10.13 Examples of Defining Constraints............... ............... .............. ................ .............. ............. 10-16

    10.13.1 Privileges Needed to Define Constraints .................................................................... 10-17

    10.13.2 Naming Constraints .............. .............. ................ .............. ............... .............. ............... 10-17

    10.14 Enabling and Disabling Constraints ................................................................................... 10-18

    10.14.1 Why Disable Constraints? ............................................................................................. 10-1810.14.2 Creating Enabled Constraints (Default) ............... .............. ............... ............... ........... 10-18

    10.14.3 Creating Disabled Constraints...................................................................................... 10-19

    10.14.4 Enabling Existing Constraints....................... ............... ............... ............... ............... .... 10-19

    10.14.5 Disabling Existing Constraints ..................................................................................... 10-20

    10.14.6 Guidelines for Enabling and Disabling Key Constraints............. ................ ............. 10-20

    10.14.7 Fixing Constraint Exceptions ........................................................................................ 10-21

    10.15 Modifying Constraints .......................................................................................................... 10-21

    10.16 Renaming Constraints........................................................................................................... 10-22

    10.17 Dropping Constraints.................. ............... .............. ............... .............. ................ .............. .. 10-23

    10.18 Managing FOREIGN KEY Constraints ............... .............. ................ .............. ............... .... 10-24

    10.18.1 Data Types and Names for Foreign Key Columns ............... .............. ................ ....... 10-2410.18.2 Limit on Columns in Composite Foreign Keys.......................................................... 10-24

    10.18.3 Foreign Key References Primary Key by Default ...................................................... 10-24

    10.18.4 Privileges Required to Create FOREIGN KEY Constraints.............. ............... ......... 10-24

    10.18.5 Choosing How Foreign Keys Enforce Referential Integrity................... .............. .... 10-24

    10.19 Viewing Information About Constraints......... ............... ................ ............... .............. ....... 10-25

    Part III PL/SQL for Application Developers

    11 Coding PL/SQL Subprograms and Packages

    11.1 Overview of PL/SQL Subprograms ..................................................................................... 11-111.2 Overview of PL/SQL Packages ............................................................................................. 11-2

    11.3 Overview of PL/SQL Units.................................................................................................... 11-3

    11.3.1 PLSQL_OPTIMIZE_LEVEL Compilation Parameter.................................................. 11-4

    11.4 Creating PL/SQL Subprograms and Packages ................................................................... 11-6

    11.4.1 Privileges Needed to Create Subprograms and Packages................. ................ ......... 11-6

    11.4.2 Creating Subprograms and Packages............................................................................ 11-6

    11.4.3 PL/SQL Object Size Limits......... .............. ............... .............. ................ .............. ............ 11-7

    11.4.4 PL/SQL Data Types ......................................................................................................... 11-7

    11.4.4.1 PL/SQL Scalar Data Types ...................................................................................... 11-8

    11.4.4.2 PL/SQL Composite Data Types.............................................................................. 11-9

    11.4.4.3 Abstract Data Types................................................................................................ 11-1011.4.5 Returning Result Sets to Clients ................................................................................... 11-10

    11.4.5.1 Advantages of Cursor Variables ........................................................................... 11-11

    11.4.5.2 Disadvantages of Cursor Variables........... ................ .............. ............... .............. . 11-11

    11.4.5.3 Returning Query Results Implicitly............. ................ ............... ............... ........... 11-14

    11.4.6 Returning Large Amounts of Data from a Function ................................................. 11-14

    11.4.7 PL/SQL Function Result Cache.......... ............... ............... .............. ............... .............. . 11-15

    11.4.8 Overview of Bulk Binding............................................................................................. 11-15

  • 7/21/2019 12c dev guide.pdf

    10/708

    x

    11.4.8.1 DML Statements that Reference Collections ....................................................... 11-16

    11.4.8.2 SELECT Statements that Reference Collections ............... ............... ................ .... 11-16

    11.4.8.3 FOR Loops that Reference Collections and Return DML............. ............... ...... 11-17

    11.4.9 PL/SQL Dynamic SQL .................................................................................................. 11-18

    11.5 Altering PL/SQL Subprograms and Packages.................. ............... ............... ............... ... 11-18

    11.6 Dropping PL/SQL Subprograms and Packages ............................................................... 11-19

    11.7 Compiling PL/SQL Units for Native Execution ............................................................... 11-1911.8 Invoking Stored PL/SQL Subprograms.............. .............. ............... .............. ............... ..... 11-19

    11.8.1 Privileges Required to Invoke a Stored Subprogram................ .............. ............... ... 11-20

    11.8.2 Invoking a Subprogram Interactively from Oracle Tools............. .............. .............. 11-20

    11.8.3 Invoking a Subprogram from Another Subprogram ................................................ 11-22

    11.8.4 Invoking a Remote Subprogram .................................................................................. 11-23

    11.8.4.1 Synonyms for Remote Subprograms.................................................................... 11-24

    11.8.4.2 Transactions That Invoke Remote Subprograms................ .............. ............... ... 11-25

    11.9 Invoking Stored PL/SQL Functions from SQL Statements................ .............. ............... 11-25

    11.9.1 Why Invoke PL/SQL Functions from SQL Statements?...................... ............... ...... 11-26

    11.9.2 Where PL/SQL Functions Can Appear in SQL Statements................... ............... ... 11-26

    11.9.3 When PL/SQL Functions Can Appear in SQL Expressions .................................... 11-2711.9.4 Controlling Side Effects of PL/SQL Functions Invoked from SQL Statements.... 11-27

    11.9.4.1 Restrictions on Functions Invoked from SQL Statements .............. ................ ... 11-28

    11.9.4.2 PL/SQL Functions Invoked from Parallelized SQL Statements ...................... 11-29

    11.9.4.3 PRAGMA RESTRICT_REFERENCES .................................................................. 11-30

    11.10 Debugging Stored Subprograms ......................................................................................... 11-33

    11.10.1 PL/Scope.......................................................................................................................... 11-33

    11.10.2 PL/SQL Hierarchical Profiler ....................................................................................... 11-33

    11.10.3 Compiling Code for Debugging................................................................................... 11-34

    11.10.4 Privileges for Debugging PL/SQL and Java Stored Subprograms.............. ........... 11-34

    11.10.5 DBMS_DEBUG Package ................................................................................................ 11-35

    11.11 Package Invalidations and Session State ................. .............. ............... ............... .............. . 11-35

    12 Using PL/Scope

    12.1 Specifying Identifier Collection ............................................................................................. 12-1

    12.2 PL/Scope Identifier Data for STANDARD and DBMS_STANDARD................ ............. 12-2

    12.2.1 Do You Need STANDARD and DBMS_STANDARD Identifier Data? ................... 12-2

    12.2.2 Does Your Database Have STANDARD and DBMS_STANDARD Identifier Data? ........12-2

    12.2.3 Recompiling STANDARD and DBMS_STANDARD.................................................. 12-3

    12.2.4 Running utlrp.sql to Recompile Invalid PL/SQL Objects.......................................... 12-4

    12.3How Much Space is PL/Scope Data Using? ........................................................................

    12-4

    12.4 Viewing PL/Scope Data ......................................................................................................... 12-5

    12.4.1 Static Data Dictionary Views .......................................................................................... 12-5

    12.4.1.1 Unique Keys ............................................................................................................... 12-5

    12.4.1.2 Context........................................................................................................................ 12-5

    12.4.1.3 Signature..................................................................................................................... 12-7

    12.4.2 Demo Tool.......................................................................................................................... 12-8

    12.4.3 SQL Developer .................................................................................................................. 12-8

    12.5 Identifier Types that PL/Scope Collects................. .............. ............... .............. ................ ... 12-8

  • 7/21/2019 12c dev guide.pdf

    11/708

    xi

    12.6 Usages that PL/Scope Reports .............................................................................................. 12-9

    12.7 Sample PL/Scope Session..................... .............. ................ .............. ............... .............. ....... 12-10

    13 Using the PL/SQL Hierarchical Profiler

    13.1 Overview of PL/SQL Hierarchical Profiler ......................................................................... 13-1

    13.2 Collecting Profile Data ............................................................................................................ 13-2

    13.3 Understanding Raw Profiler Output .................................................................................... 13-3

    13.3.1 Namespaces of Tracked Subprograms.......................................................................... 13-6

    13.3.2 Special Function Names........... ............... .............. ................ .............. ............... .............. 13-6

    13.4 Analyzing Profile Data............................................................................................................ 13-7

    13.4.1 Creating Hierarchical Profiler Tables ............................................................................ 13-7

    13.4.2 Understanding Hierarchical Profiler Tables................................................................. 13-8

    13.4.2.1 Hierarchical Profiler Database Table Columns..................................................... 13-8

    13.4.2.2 Distinguishing Between Overloaded Subprograms........................ ............... .... 13-10

    13.4.2.3 Hierarchical Profiler Tables for Sample PL/SQL Procedure ............. .............. . 13-10

    13.4.2.4 Examples of Calls to DBMS_HPROF.analyze with Options.......... ............... .... 13-12

    13.5 plshprof Utility....................................................................................................................... 13-13

    13.5.1 plshprof Options............................................................................................................. 13-14

    13.5.2 HTML Report from a Single Raw Profiler Output File ............... .............. ............... . 13-14

    13.5.2.1 First Page of Report................................................................................................. 13-14

    13.5.2.2 Function-Level Reports......... ............... ............... .............. ............... ............... ........ 13-15

    13.5.2.3 Module-Level Reports ............................................................................................ 13-16

    13.5.2.4 Namespace-Level Reports...................................................................................... 13-16

    13.5.2.5 Parents and Children Report for a Function ....................................................... 13-17

    13.5.3 HTML Difference Report from Two Raw Profiler Output Files.............. ............... . 13-18

    13.5.3.1 Difference Report Conventions ............................................................................. 13-19

    13.5.3.2 First Page of Difference Report..................... .............. .............. ................ ............. 13-19

    13.5.3.3 Function-Level Difference Reports ....................................................................... 13-2013.5.3.4 Module-Level Difference Reports......................................................................... 13-21

    13.5.3.5 Namespace-Level Difference Reports .................................................................. 13-22

    13.5.3.6 Parents and Children Difference Report for a Function ............... ................ ..... 13-22

    14 Developing PL/SQL Web Applications

    14.1 Overview of PL/SQL Web Applications................... ................ .............. ............... .............. 14-1

    14.2 Implementing PL/SQL Web Applications..................... ............... .............. ................ ......... 14-2

    14.2.1 PL/SQL Gateway ............................................................................................................. 14-2

    14.2.1.1 mod_plsql ................................................................................................................... 14-2

    14.2.1.2 Embedded PL/SQL Gateway.................................................................................. 14-3

    14.2.2 PL/SQL Web Toolkit ....................................................................................................... 14-314.3 Using mod_plsql Gateway to Map Client Requests to a PL/SQL Web Application .... 14-4

    14.4 Using Embedded PL/SQL Gateway..................................................................................... 14-4

    14.4.1 How Embedded PL/SQL Gateway Processes Client Requests............... ............... ... 14-5

    14.4.2 Installing Embedded PL/SQL Gateway ....................................................................... 14-6

    14.4.3 Configuring Embedded PL/SQL Gateway .................................................................. 14-6

    14.4.3.1 Configuring Embedded PL/SQL Gateway: Overview............. ............... ............ 14-6

    14.4.3.2 Configuring User Authentication for Embedded PL/SQL Gateway ............... . 14-8

  • 7/21/2019 12c dev guide.pdf

    12/708

    xii

    14.4.4 Invoking PL/SQL Stored Subprograms Through Embedded PL/SQL Gateway 14-17

    14.4.5 Securing Application Access with Embedded PL/SQL Gateway............. .............. 14-17

    14.4.6 Restrictions in Embedded PL/SQL Gateway................ ................ .............. ............... 14-18

    14.4.7 Using Embedded PL/SQL Gateway: Scenario............. ............... .............. ................ . 14-18

    14.5 Generating HTML Output with PL/SQL.............. ............... ............... .............. ................ . 14-20

    14.6 Passing Parameters to PL/SQL Web Applications.............. ................ ............... .............. 14-21

    14.6.1 Passing List and Dropdown-List Parameters from an HTML Form ...................... 14-2114.6.2 Passing Option and Check Box Parameters from an HTML Form ......................... 14-22

    14.6.3 Passing Entry-Field Parameters from an HTML Form ............................................. 14-22

    14.6.4 Passing Hidden Parameters from an HTML Form.................... ............... .............. ... 14-24

    14.6.5 Uploading a File from an HTML Form ....................................................................... 14-24

    14.6.6 Submitting a Completed HTML Form ........................................................................ 14-24

    14.6.7 Handling Missing Input from an HTML Form............. ................ .............. ............... 14-24

    14.6.8 Maintaining State Information Between Web Pages ............... ................ ............... ... 14-25

    14.7 Performing Network Operations in PL/SQL Subprograms .............. .............. ............... 14-25

    14.7.1 Sending E-Mail from PL/SQL ...................................................................................... 14-26

    14.7.2 Getting a Host Name or Address from PL/SQL ....................................................... 14-27

    14.7.3 Using TCP/IP Connections from PL/SQL ................................................................. 14-2714.7.4 Retrieving HTTP URL Contents from PL/SQL ......................................................... 14-27

    14.7.5 Using Tables, Image Maps, Cookies, and CGI Variables from PL/SQL ............ ... 14-29

    15 Using Continuous Query Notification (CQN)

    15.1 About Object Change Notification (OCN)........................................................................... 15-2

    15.2 About Query Result Change Notification (QRCN) ............................................................ 15-2

    15.2.1 Guaranteed Mode............................................................................................................. 15-3

    15.2.2 Best-Effort Mode............................................................................................................... 15-3

    15.3 Events that Generate Notifications.................... .............. ............... .............. ............... .......... 15-4

    15.3.1 Committed DML Transactions ....................................................................................... 15-515.3.2 Committed DDL Statements........................................................................................... 15-5

    15.3.3 Deregistration.................................................................................................................... 15-6

    15.3.4 Global Events..................................................................................................................... 15-6

    15.4 Notification Contents .............................................................................................................. 15-7

    15.5 Good Candidates for CQN ..................................................................................................... 15-7

    15.6 Creating CQN Registrations.................... ............... .............. ................ ............... .............. ... 15-10

    15.7 Using PL/SQL to Create CQN Registrations .................................................................... 15-10

    15.7.1 PL/SQL CQN Registration Interface........................................................................... 15-10

    15.7.2 CQN Registration Options............................................................................................ 15-11

    15.7.2.1 Notification Type Option ....................................................................................... 15-11

    15.7.2.2 QRCN Mode (QRCN Notification Type Only) ................................................... 15-1215.7.2.3 ROWID Option ........................................................................................................ 15-12

    15.7.2.4 Operations Filter Option (OCN Notification Type Only) ................................. 15-12

    15.7.2.5 Transaction Lag Option (OCN Notification Type Only) .............. ............... ...... 15-13

    15.7.2.6 Notification Grouping Options ............................................................................. 15-13

    15.7.2.7 Reliable Option ........................................................................................................ 15-14

    15.7.2.8 Purge-on-Notify and Timeout Options............... .............. ............... .............. ...... 15-14

    15.7.3 Prerequisites for Creating CQN Registrations ........................................................... 15-15

    15.7.4 Queries that Can Be Registered for Object Change Notification (OCN).............. .. 15-15

  • 7/21/2019 12c dev guide.pdf

    13/708

    xiii

    15.7.5 Queries that Can Be Registered for Query Result Change Notification (QRCN) . 15-15

    15.7.5.1 Queries that Can Be Registered for QRCN in Guaranteed Mode.................... 15-16

    15.7.5.2 Queries that Can Be Registered for QRCN Only in Best-Effort Mode ............ 15-17

    15.7.5.3 Queries that Cannot Be Registered for QRCN in Either Mode ........................ 15-17

    15.7.6 Using PL/SQL to Register Queries for CQN.......... ................ .............. ............... ....... 15-18

    15.7.6.1 Creating a PL/SQL Notification Handler.................... ............... ............... .......... 15-18

    15.7.6.2 Creating a CQ_NOTIFICATION$_REG_INFO Object ...................................... 15-1915.7.6.3 Identifying Individual Queries in a Notification ............... .............. ............... .... 15-22

    15.7.6.4 Adding Queries to an Existing Registration.............. ............... .............. ............. 15-22

    15.7.7 Best Practices for CQN Registrations................ ............... ............... .............. ............... 15-23

    15.7.8 Troubleshooting CQN Registrations ........................................................................... 15-23

    15.7.9 Deleting Registrations.................................................................................................... 15-24

    15.7.10 Configuring CQN: Scenario .......................................................................................... 15-24

    15.7.10.1 Creating a PL/SQL Notification Handler.................... ............... ............... .......... 15-25

    15.7.10.2 Registering the Queries .......................................................................................... 15-27

    15.8 Using OCI to Create CQN Registrations............................................................................ 15-29

    15.8.1 Using OCI for Query Result Set Notifications.................. ............... ............... ............ 15-29

    15.8.2 Using OCI to Register a Continuous Query Notification............... ................ .......... 15-2915.8.3 Using OCI Subscription Handle Attributes for Continuous Query Notification . 15-31

    15.8.4 Using OCI_ATTR_CQ_QUERYID Attribute.............................................................. 15-32

    15.8.5 Using OCI Continuous Query Notification Descriptors.............. ................ ............. 15-33

    15.8.5.1 OCI_DTYPE_CHDES.............................................................................................. 15-33

    15.8.6 Demonstrating Continuous Query Notification in an OCI Sample Program ....... 15-34

    15.9 Querying CQN Registrations............................................................................................... 15-44

    15.10 Interpreting Notifications ..................................................................................................... 15-45

    15.10.1 Interpreting a CQ_NOTIFICATION$_DESCRIPTOR Object .................................. 15-45

    15.10.2 Interpreting a CQ_NOTIFICATION$_TABLE Object..................... ................ .......... 15-46

    15.10.3 Interpreting a CQ_NOTIFICATION$_QUERY Object.............. ................ ............... . 15-46

    15.10.4 Interpreting a CQ_NOTIFICATION$_ROW Object.................... ............... ............... 15-47

    Part IV Advanced Topics for Application Developers

    16 Using Oracle Flashback Technology

    16.1 Overview of Oracle Flashback Technology ......................................................................... 16-1

    16.1.1 Application Development Features ............................................................................... 16-2

    16.1.2 Database Administration Features..................... .............. ............... ............... ............... . 16-3

    16.2 Configuring Your Database for Oracle Flashback Technology....................... ............... ... 16-3

    16.2.1 Configuring Your Database for Automatic Undo Management ............................... 16-3

    16.2.2 Configuring Your Database for Oracle Flashback Transaction Query................. .... 16-416.2.3 Configuring Your Database for Flashback Transaction............... ................ ............... 16-4

    16.2.4 Enabling Oracle Flashback Operations on Specific LOB Columns ........................... 16-5

    16.2.5 Granting Necessary Privileges........................................................................................ 16-5

    16.3 Using Oracle Flashback Query (SELECT AS OF) ............................................................... 16-6

    16.3.1 Example of Examining and Restoring Past Data ......................................................... 16-7

    16.3.2 Guidelines for Oracle Flashback Query ........................................................................ 16-7

    16.4 Using Oracle Flashback Version Query.................... ............... ................ .............. ............... 16-8

  • 7/21/2019 12c dev guide.pdf

    14/708

    xiv

    16.5 Using Oracle Flashback Transaction Query....................... ................ .............. ............... ... 16-10

    16.6 Using Oracle Flashback Transaction Query with Oracle Flashback Version Query ... 16-10

    16.7 Using DBMS_FLASHBACK Package ................................................................................. 16-13

    16.8 Using Flashback Transaction............. ............... .............. ............... ............... ............... ......... 16-13

    16.8.1 Dependent Transactions ................................................................................................ 16-14

    16.8.2 TRANSACTION_BACKOUT Parameters .................................................................. 16-15

    16.8.3 TRANSACTION_BACKOUT Reports.................. ............... ................ .............. .......... 16-1516.8.3.1 *_FLASHBACK_TXN_STATE............................................................................... 16-15

    16.8.3.2 *_FLASHBACK_TXN_REPORT.................. ............... .............. .............. ............... 16-16

    16.9 Using Flashback Data Archive.............. ................ .............. ............... .............. ................ .... 16-16

    16.9.1 Creating a Flashback Data Archive................. ............... ............... ............... ............... . 16-17

    16.9.2 Altering a Flashback Data Archive .............................................................................. 16-18

    16.9.3 Dropping a Flashback Data Archive................ ............... ............... ............... .............. . 16-19

    16.9.4 Specifying the Default Flashback Data Archive.................... .............. ............... ........ 16-19

    16.9.5 Enabling and Disabling Flashback Data Archive ...................................................... 16-20

    16.9.6 DDL Statements on Tables Enabled for Flashback Data Archive........... ............... .. 16-21

    16.9.7 Viewing Flashback Data Archive Data.................... ............... ................ .............. ....... 16-22

    16.9.8 Flashback Data Archive Scenarios ............................................................................... 16-2216.9.8.1 Scenario: Using Flashback Data Archive to Enforce Digital Shredding.......... 16-22

    16.9.8.2 Scenario: Using Flashback Data Archive to Access Historical Data ............... . 16-23

    16.9.8.3 Scenario: Using Flashback Data Archive to Generate Reports ......................... 16-23

    16.9.8.4 Scenario: Using Flashback Data Archive for Auditing ...................................... 16-23

    16.9.8.5 Scenario: Using Flashback Data Archive to Recover Data ................................ 16-24

    16.10 General Guidelines for Oracle Flashback Technology ..................................................... 16-24

    16.11 Performance Guidelines for Oracle Flashback Technology...................... ................ ....... 16-26

    16.12 Multitenant Container Database Restrictions for Oracle Flashback Technology......... 16-26

    17 Choosing a Programming Environment

    17.1 Overview of Application Architecture ................................................................................. 17-2

    17.1.1 Client/Server Architecture.............................................................................................. 17-2

    17.1.2 Server-Side Programming ............................................................................................... 17-2

    17.1.3 Two-Tier and Three-Tier Architecture .......................................................................... 17-2

    17.2 Overview of the Program Interface................ ............... .............. ............... .............. ............. 17-3

    17.2.1 User Interface .................................................................................................................... 17-3

    17.2.2 Stateful and Stateless User Interfaces ............................................................................ 17-3

    17.3 Overview of PL/SQL .............................................................................................................. 17-4

    17.4 Overview of Oracle Database Java Support....................... .............. ................ .............. ...... 17-4

    17.4.1 Overview of Oracle JVM.................................................................................................. 17-4

    17.4.2 Overview of Oracle JDBC................................................................................................ 17-517.4.2.1 Oracle JDBC Drivers ................................................................................................. 17-6

    17.4.2.2 Sample JDBC 2.0 Program........................................................................................ 17-7

    17.4.2.3 Sample Pre-2.0 JDBC Program ................................................................................ 17-8

    17.4.3 Overview of Oracle SQLJ............ .............. ............... .............. .............. ............... ............. 17-9

    17.4.3.1 Benefits of SQLJ ....................................................................................................... 17-10

    17.4.3.2 SQLJ Stored Subprograms in the Server .............................................................. 17-10

    17.4.4 Comparing Oracle JDBC and Oracle SQLJ ................................................................. 17-10

    17.4.5 Overview of Oracle JPublisher ..................................................................................... 17-11

  • 7/21/2019 12c dev guide.pdf

    15/708

    xv

    17.4.6 Overview of Java Stored Subprograms....................................................................... 17-11

    17.4.7 Overview of Oracle Database Web Services.............. .............. ................ .............. ..... 17-12

    17.5 Choosing PL/SQL or Java.................................................................................................... 17-13

    17.5.1 Similarities of PL/SQL and Java .................................................................................. 17-13

    17.5.2 PL/SQL Advantages Over Java................. .............. ............... .............. ............... ......... 17-14

    17.5.3 Java Advantages Over PL/SQL................. ............. ................ .............. ............... ......... 17-14

    17.6 Overview of Precompilers .................................................................................................... 17-1517.6.1 Overview of the Pro*C/C++ Precompiler .................................................................. 17-15

    17.6.2 Overview of the Pro*COBOL Precompiler ................................................................. 17-17

    17.7 Overview of OCI and OCCI................................................................................................. 17-18

    17.7.1 Advantages of OCI and OCCI ...................................................................................... 17-19

    17.7.2 OCI and OCCI Functions.......... .............. ................ .............. ............... .............. ............ 17-20

    17.7.3 Procedural and Nonprocedural Elements of OCI and OCCI Applications ........... 17-20

    17.7.4 Building an OCI or OCCI Application ........................................................................ 17-21

    17.8 Choosing a Precompiler or OCI........................................................................................... 17-21

    17.9 Overview of Oracle Data Provider for .NET (ODP.NET) ............... .............. ............... .... 17-22

    17.10 Overview of OraOLEDB....................................................................................................... 17-23

    18 Developing Applications with Multiple Programming Languages

    18.1 Overview of Multilanguage Programs................................................................................. 18-1

    18.2 What Is an External Procedure?......... ............... ............... .............. ............... ............... .......... 18-3

    18.3 Overview of Call Specification for External Procedures................. ............... ................ .... 18-3

    18.4 Loading External Procedures................................................................................................. 18-4

    18.4.1 Define the C Procedures .................................................................................................. 18-5

    18.4.2 Set Up the Environment................................................................................................... 18-5

    18.4.3 Identify the DLL................................................................................................................ 18-8

    18.4.4 Publish the External Procedures......... ............... ............... ............... .............. ................ . 18-9

    18.5 Publishing External Procedures...................... ............... .............. ................ .............. ............ 18-918.5.1 AS LANGUAGE Clause for Java Class Methods.................... .............. ................ ..... 18-10

    18.5.2 AS LANGUAGE Clause for External C Procedures................... ............... .............. .. 18-10

    18.5.2.1 LIBRARY .................................................................................................................. 18-10

    18.5.2.2 NAME ...................................................................................................................... 18-10

    18.5.2.3 LANGUAGE ........................................................................................................... 18-11

    18.5.2.4 CALLING STANDARD.......................................................................................... 18-11

    18.5.2.5 WITH CONTEXT ............... .............. .............. ............... ............... .............. ............. 18-11

    18.5.2.6 PARAMETERS ............. ............... ............... .............. ............... .............. .............. .... 18-11

    18.5.2.7 AGENT IN................................................................................................................ 18-11

    18.6 Publishing Java Class Methods.................. ................ .............. ............... .............. ............... 18-11

    18.7 Publishing External C Procedures............... ............... ............... ............... ............... ............ 18-1218.8 Locations of Call Specifications ........................................................................................... 18-12

    18.8.1 Example: Locating a Call Specification in a PL/SQL Package.......................... ....... 18-13

    18.8.2 Example: Locating a Call Specification in a PL/SQL Package Body ................. ..... 18-13

    18.8.3 Example: Locating a Call Specification in an ADT Specification ............................ 18-13

    18.8.4 Example: Locating a Call Specification in an ADT Body.................. ............... ......... 18-14

    18.8.5 Example: Java with AUTHID.......... ............... .............. ................ ............... .............. .... 18-14

    18.8.6 Example: C with Optional AUTHID...................... ................ .............. ............... ......... 18-14

    18.8.7 Example: Mixing Call Specifications in a Package .................................................... 18-14

  • 7/21/2019 12c dev guide.pdf

    16/708

    xvi

    18.9 Passing Parameters to External C Procedures with Call Specifications ............. ........... 18-15

    18.9.1 Specifying Data Types......... ............... ................ .............. ............... .............. ................ . 18-16

    18.9.2 External Data Type Mappings ...................................................................................... 18-17

    18.9.3 Passing Parameters BY VALUE or BY REFERENCE ................................................ 18-19

    18.9.4 Declaring Formal Parameters ....................................................................................... 18-19

    18.9.5 Overriding Default Data Type Mapping............ ............... ............... ............... ............ 18-20

    18.9.6 Specifying Properties ..................................................................................................... 18-2018.9.6.1 INDICATOR............................................................................................................. 18-22

    18.9.6.2 LENGTH and MAXLEN ........................................................................................ 18-22

    18.9.6.3 CHARSETID and CHARSETFORM..................................................................... 18-22

    18.9.6.4 Repositioning Parameters ...................................................................................... 18-23

    18.9.6.5 SELF........................................................................................................................... 18-23

    18.9.6.6 BY REFERENCE ...................................................................................................... 18-25

    18.9.6.7 WITH CONTEXT..................................................................................................... 18-26

    18.9.6.8 Interlanguage Parameter Mode Mappings............... ............... ................ ............ 18-26

    18.10 Running External Procedures with CALL Statements ............. ................ .............. .......... 18-26

    18.10.1 Preconditions for External Procedures .............. ............... ............... ............... ............. 18-27

    18.10.1.1 Privileges of External Procedures ......................................................................... 18-2718.10.1.2 Managing Permissions................. ............... .............. ............... .............. ................ . 18-28

    18.10.1.3 Creating Synonyms for External Procedures ...................................................... 18-28

    18.10.2 CALL Statement Syntax..................... .............. ................ .............. ............... ............... .. 18-28

    18.10.3 Calling Java Class Methods................. ............... .............. ................ .............. ............... 18-29

    18.10.4 Calling External C Procedures.............. ............... ............... .............. ................ ............ 18-29

    18.11 Handling Errors and Exceptions in Multilanguage Programs................... ............... ...... 18-30

    18.12 Using Service Routines with External C Procedures.............. ................ .............. ............ 18-30

    18.12.1 OCIExtProcAllocCallMemory ...................................................................................... 18-30

    18.12.2 OCIExtProcRaiseExcp.................................................................................................... 18-34

    18.12.3 OCIExtProcRaiseExcpWithMsg....................... ............... ............... .............. ................ . 18-35

    18.13 Doing Callbacks with External C Procedures.................. ............... ............... .............. ...... 18-36

    18.13.1 OCIExtProcGetEnv......................................................................................................... 18-36

    18.13.2 Object Support for OCI Callbacks ................................................................................ 18-38

    18.13.3 Restrictions on Callbacks............................................................................................... 18-38

    18.13.4 Debugging External C Procedures................ ............... ................ ............... .............. ... 18-39

    18.13.5 Example: Calling an External C Procedure.................... ................ .............. ............... 18-39

    18.13.6 Global Variables in External C Procedures................ .............. ............... .............. ...... 18-40

    18.13.7 Static Variables in External C Procedures................................................................... 18-40

    18.13.8 Restrictions on External C Procedures ........................................................................ 18-41

    19 Developing Applications with Oracle XA

    19.1 X/Open Distributed Transaction Processing (DTP)............... .............. ................ .............. 19-2

    19.1.1 DTP Terminology ............................................................................................................. 19-2

    19.1.2 Required Public Information .......................................................................................... 19-5

    19.2 Oracle XA Library Subprograms........................................................................................... 19-5

    19.2.1 Oracle XA Library Subprograms.................................................................................... 19-5

    19.2.2 Oracle XA Interface Extensions ...................................................................................... 19-6

    19.3 Developing and Installing XA Applications........................................................................ 19-7

    19.3.1 DBA or System Administrator Responsibilities........................................................... 19-7

  • 7/21/2019 12c dev guide.pdf

    17/708

    xvii

    19.3.2 Application Developer Responsibilities........................................................................ 19-8

    19.3.3 Defining the xa_open String............ ............... .............. ................ .............. ............... ...... 19-8

    19.3.3.1 Syntax of the xa_open String ................................................................................... 19-8

    19.3.3.2 Required Fields for the xa_open String.................................................................. 19-9

    19.3.3.3 Optional Fields for the xa_open String............. ............... .............. .............. ........... 19-9

    19.3.4 Using Oracle XA with Precompilers............................................................................ 19-11

    19.3.4.1 Using Precompilers with the Default Database .................................................. 19-1119.3.4.2 Using Precompilers with a Named Database...................... .............. ................ .. 19-11

    19.3.5 Using Oracle XA with OCI............................................................................................ 19-12

    19.3.6 Managing Transaction Control with Oracle XA ........................................................ 19-13

    19.3.7 Examples of Precompiler Applications ....................................................................... 19-14

    19.3.8 Migrating Precompiler or OCI Applications to TPM Applications ........................ 19-14

    19.3.9 Managing Oracle XA Library Thread Safety.............................................................. 19-15

    19.3.9.1 Specifying Threading in the Open String ............................................................ 19-16

    19.3.9.2 Restrictions on Threading in Oracle XA .............................................................. 19-16

    19.3.10 Using the DBMS_XA Package ...................................................................................... 19-16

    19.4 Troubleshooting XA Applications............... ............... ................ .............. ............... ............ 19-19

    19.4.1 Accessing Oracle XA Trace Files .................................................................................. 19-1919.4.1.1 xa_open String DbgFl.......... ............... ............... .............. ................ .............. .......... 19-20

    19.4.1.2 Trace File Locations................................................................................................. 19-20

    19.4.2 Managing In-Doubt or Pending Oracle XA Transactions......... ................ ............... . 19-20

    19.4.3 Using SYS Account Tables to Monitor Oracle XA Transactions................... ........... 19-20

    19.5 Oracle XA Issues and Restrictions....................................................................................... 19-21

    19.5.1 Using Database Links in Oracle XA Applications ..................................................... 19-21

    19.5.2 Managing Transaction Branches in Oracle XA Applications....................... ............ 19-22

    19.5.3 Using Oracle XA with Oracle Real Application Clusters (Oracle RAC) ................ 19-22

    19.5.3.1 GLOBAL_TXN_PROCESSES Initialization Parameter............... ................ ....... 19-23

    19.5.3.2 Managing Transaction Branches on Oracle RAC ............................................... 19-23

    19.5.3.3 Managing Instance Recovery in Oracle RAC with DTP Services (10.2).......... 19-24

    19.5.3.4 Global Uniqueness of XIDs in Oracle RAC ......................................................... 19-25

    19.5.3.5 Tight and Loose Coupling...................................................................................... 19-25

    19.5.4 SQL-Based Oracle XA Restrictions................... .............. ............... ............... .............. .. 19-25

    19.5.4.1 Rollbacks and Commits.......................................................................................... 19-26

    19.5.4.2 DDL Statements ....................................................................................................... 19-26

    19.5.4.3 Session State ............................................................................................................. 19-26

    19.5.4.4 EXEC SQL................................................................................................................. 19-26

    19.5.5 Miscellaneous Restrictions ............................................................................................ 19-26

    20 Developing Applications with the Publish-Subscribe Model

    20.1 Introduction to the Publish-Subscribe Model............. ............... ............... ............... ............ 20-1

    20.2 Publish-Subscribe Architecture........... ............... ............... ............... ............... .............. ......... 20-2

    20.2.1 Database Events................................................................................................................ 20-2

    20.2.2 Oracle Advanced Queuing.............................................................................................. 20-2

    20.2.3 Client Notification ............................................................................................................ 20-2

    20.3 Publish-Subscribe Concepts ................................................................................................... 20-3

    20.4 Examples of a Publish-Subscribe Mechanism ..................................................................... 20-4

  • 7/21/2019 12c dev guide.pdf

    18/708

    xviii

    21 Using the Oracle ODBC Driver

    21.1 About Oracle ODBC Driver.......... ................ ............. ................ ............... .............. ................ 21-1

    21.2 For All Users............................................................................................................................. 21-2

    21.2.1 Oracle ODBC Driver......................................................................................................... 21-2

    21.2.1.1 What is the Oracle ODBC Driver ............................................................................ 21-3

    21.2.1.2 New and Changed Features..................................................................................... 21-5

    21.2.1.3 Features Not Supported ........................................................................................... 21-8

    21.2.1.4 Files Created by the Installation.............................................................................. 21-8

    21.2.1.5 Driver Conformance Levels..................................................................................... 21-9

    21.2.1.6 Known Limitations.................................................................................................. 21-10

    21.2.2 Configuration Tasks....................................................................................................... 21-10

    21.2.2.1 Configuring Oracle Net Services.............. ............... .............. ............... .............. ... 21-10

    21.2.2.2 Configuring the Data Source ..........................................