6b Continuing Past Exceptions



Similar documents
Error Management in Oracle PL/SQL

Best Practices for Dynamic SQL

Bullet Proof Your PL/SQL

Making the Most of Oracle PL/SQL Error Management Features

Best Practices For PL/SQL Development in Oracle Application Express

OPP ODTUG Kaleidoscope. An ODTUG SP* Oracle PL/SQL Programming Conference. WOW-Wide Open World, Wide Open Web!

Oracle 11g PL/SQL training

Oracle Database: Develop PL/SQL Program Units

Handling Exceptions. Schedule: Timing Topic. 45 minutes Lecture 20 minutes Practice 65 minutes Total

Handling Exceptions. Schedule: Timing Topic 45 minutes Lecture 20 minutes Practice 65 minutes Total

Oracle PL/SQL Programming


Handling Exceptions. Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 8-1

Oracle PL/SQL Best Practices

Handling Exceptions. Copyright 2008, Oracle. All rights reserved.

Automated Testing Options for PL/SQL Steven Feuerstein PL/SQL Evangelist, Quest Software

Oracle Database: Program with PL/SQL

Oracle Database: Program with PL/SQL

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

Duration Vendor Audience 5 Days Oracle Developers, Technical Consultants, Database Administrators and System Analysts

Oracle Database: SQL and PL/SQL Fundamentals

Oracle Database: Program with PL/SQL

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Oracle Database 11g: Program with PL/SQL

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

PL/SQL (Cont d) Let s start with the mail_order database, shown here:

PL/SQL Coding Style Guidelines Introducing Error Handling, Tracing and Coding Standards. Author: Vishal Gupta

Oracle Database: SQL and PL/SQL Fundamentals NEW

When an exception occur a message which explains its cause is received. PL/SQL Exception message consists of three parts.

A Generic business rules validation system for ORACLE Applications

Advanced SQL Injection in Oracle databases. Esteban Martínez Fayó

Copyright 2013 wolfssl Inc. All rights reserved. 2

Oracle Database: Program with PL/SQL

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

PL/SQL Programming Workbook

Oracle 10g PL/SQL Training

Oracle Database: Program with PL/SQL

Handling PL/SQL Errors

Oracle Database: SQL and PL/SQL Fundamentals

High-Performance Oracle: Proven Methods for Achieving Optimum Performance and Availability

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

An Oracle White Paper May Guide for Developing High-Performance Database Applications

1Z0-117 Oracle Database 11g Release 2: SQL Tuning. Oracle

Business Technology Training Classes July 2010 June 2011

Virtual Private Database Features in Oracle 10g.

Oracle Database 12c: Introduction to SQL Ed 1.1

14 Triggers / Embedded SQL

news from Tom Bacon about Monday's lecture

Oracle Database 10g: Program with PL/SQL

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Handling PL/SQL Errors

Using AND in a Query: Step 1: Open Query Design

Blackboard Collaborate Introduction & Handbook

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Oracle Database 10g: Parallelism and Scalability Overview Seminar

Database Programming with PL/SQL: Learning Objectives

PL/SQL Programming Concepts: Review. Copyright 2004, Oracle. All rights reserved.

Relational Databases for the Business Analyst

Oracle Database 12c: Administration Workshop NEW

David Dye. Extract, Transform, Load

STUDY OF PL/SQL BLOCK AIM: To Study about PL/SQL block.

Oracle Database: SQL and PL/SQL Fundamentals NEW

Oracle EXAM - 1Z Oracle Database 11g Release 2: SQL Tuning. Buy Full Product.

Solving Business Pains with SQL Server Integration Services. SQL Server 2005 / 2008

OTM Performance OTM Users Conference Jim Mooney Vice President, Product Development August 11, 2015

Oracle Database 12c: SQL Tuning for Developers. Sobre o curso. Destinatários. Oracle - Linguagens. Nível: Avançado Duração: 18h

PHP Oracle Web Applications: Best Practices and Caching Strategies

Data Integration and ETL with Oracle Warehouse Builder: Part 1

Performance Implications of Various Cursor Types in Microsoft SQL Server. By: Edward Whalen Performance Tuning Corporation

Codeless Test Automation for Web Apps

Oracle Total Recall with Oracle Database 11g Release 2

Implementing Database Development Best Practices for Oracle

Course -Oracle 10g SQL (Exam Code IZ0-047) Session number Module Topics 1 Retrieving Data Using the SQL SELECT Statement

Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Introduction to PL/SQL Programming

mframe Software Development Platform KEY FEATURES

An Introduction to PL/SQL. Mehdi Azarmi

Oracle PL/SQL Injection

Oracle Database 10g: Introduction to SQL

1. INTRODUCTION TO RDBMS

Writing Control Structures

NEW AND IMPROVED: HACKING ORACLE FROM WEB. Sumit sid Siddharth 7Safe Limited UK

MicroMD EMR Tips & Tricks. Presenter: Todd Sizer, EMR Training Specialist

Creating and grading assignments

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

PRODUCT HUB STREAMLINED ITEM BATCH USER INTERFACE DEFINE IMPORT FORMATS FOR SPREADSHEET IMPORT CONSOLIDATION OF DIGITAL ASSETS THROUGH THE ITEM BATCH

Oracle Data Redaction is Broken

NEOAUG. Custom Web ADI Integrators

Microsoft Business Contact Manager Complete

Oracle Database 11g: Advanced PL/SQL

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

Navistar Direct Ship isupplier Portal. Overview and Administration for Suppliers

Webucator Free Online Technology Training Courses

Getting Started in Fireside21

Transcription:

The PL/SQL Channel Error Management in Oracle PL/SQL 6b Continuing Past Exceptions with FORALL and SAVE EXCEPTIONS Steven Feuerstein steven@stevenfeuerstein.com www.stevenfeuerstein.com www.plsqlchallenge.com

Quick Reminders Download code and PowerPoint documents from www.toadworld.com/sf (aka, "PL/SQL Obsession"). Make sure you are comfortable with the material covered in the previous lessons in this series. Basic Concepts, Defining, Raising and Handling Exceptions Copyright 2010 Feuerstein and Associates Page 2

FORALL with SAVE EXCEPTIONS - agenda Quick overview of FORALL FORALL and DML errors Impact of SAVE EXCEPTIONS Working with the SQL%BULK_EXCEPTIONS pseudo-collection Copyright 2010 Feuerstein and Associates Page 3

Quick Overview of FORALL PROCEDURE upd_for_dept (newsal_in IN NUMBER, list_of_emps_in IN DBMS_SQL.NUMBER_TABLE) IS BEGIN FORALL indx IN list_of_emps_in.first.. list_of_emps_in.last UPDATE employees SET salary = newsal_in WHERE employee_id = list_of_emps_in (indx); END; FORALL offers the ability to "bulk process" DML statements. Use of FORALL can improve DML performance by an order of magnitude. It is covered in depth in the " Turbo-charge PL/SQL Execution with Bulk Processing" lesson. In this lesson, we will cover only the exception handlingspecific aspects of FORALL: SAVE EXCEPTIONS. forall_timing.sql Copyright 2010 Feuerstein and Associates Page 4

FORALL and DML Errors FORALLs typically execute multiple DML statements. When an exception occurs in one of those DML statement, the default behavior is: That statement is rolled back and the FORALL stops. All (previous) successful statements are not rolled back. But FORALL is often used for "batch" execution of DML. What if you want the FORALL processing to continue, even if an error occurs in one of the statements? Just add the SAVE EXCEPTIONS clause! Copyright 2010 Feuerstein and Associates Page 5

SAVE EXCEPTIONS and FORALL Oracle PL/SQL Programming PROCEDURE upd_for_dept (newsal_in IN NUMBER, list_of_emps_in IN DBMS_SQL.NUMBER_TABLE) IS BEGIN FORALL indx IN list_of_emps_in.first.. list_of_emps_in.last SAVE EXCEPTIONS UPDATE employees SET salary = newsal_in WHERE employee_id = list_of_emps_in (indx); END; The SAVE EXCEPTIONS clause tells Oracle to save exception information and continue processing all of the DML statements. When the FORALL statement completes, if at least one exception occurred, Oracle then raises an exception and you check the contents of SQL%BULK_EXCEPTIONS. Copyright 2010 Feuerstein and Associates Page 6

Example: FORALL with SAVE EXCEPTIONS Add SAVE EXCEPTIONS to enable FORALL to suppress errors at the statement level. CREATE OR REPLACE PROCEDURE load_books (books_in IN book_obj_list_t) IS bulk_errors EXCEPTION; PRAGMA EXCEPTION_INIT ( bulk_errors, -24381 ); BEGIN FORALL indx IN books_in.first..books_in.last SAVE EXCEPTIONS INSERT INTO book values (books_in(indx)); EXCEPTION WHEN bulk_errors THEN FOR indx in 1..SQL%BULK_EXCEPTIONS.COUNT LOOP log_error (SQL%BULK_EXCEPTIONS(indx).ERROR_INDEX, SQL%BULK_EXCEPTIONS(indx).ERROR_CODE); END LOOP; END; If any exception is encountered, Oracle raises - 24381 when done. Allows processing of all statements, even after an error occurs. Iterate through "pseudo-collection" of errors. bulkexc.sql Copyright 2010 Feuerstein and Associates Page 7

SAVE EXCEPTIONS in Detail For each exception raised, Oracle populates the SQL%BULK_EXCEPTIONS pseudo-collection of records. The record has two fields : ERROR_INDEX and ERROR_CODE. ERROR_INDEX: the index in the bind array for which the error occurred. ERROR_CODE: the number (positive) for the error that was raised It's a pseudo-collection, because it only supports a single method: COUNT. So you iterate from 1 to SQL%BULK_EXCEPTIONS.COUNT to get information about each error. Unfortunately, it does not store the error message. Copyright 2010 Feuerstein and Associates Page 8

Conclusions FORALL is one of the most important performance enhancement features of PL/SQL You should use it whenever you execute DML statements inside a loop. But you must then also decide: what do I do when one of those statements raise an error? If you want to execute all statements, regardless of errors, then add SAVE EXCEPTIONS. And make sure to check the SQL%BULK_ECXEPTIONS pseudo collection in your exception section. Copyright 2010 Feuerstein and Associates Page 9

Next Steps Download the demo.zip if you have not already (www.toadworld.com/sf). Run the sample code yourself to reinforce the lessons. Make sure you are extremely comfortable with and looking for places in your code to use FORALL! Watch the next webinar in this series: DBMS_ERRLOG and LOG ERRORS. Copyright 2010 Feuerstein and Associates Page 10