Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 

Slides:



Advertisements
Similar presentations
ORACLE TRANSACTIONS A transaction begins with the first executable SQL statement after a commit, rollback or connection made to the Oracle engine. All.
Advertisements

Chapter 4B: More Advanced PL/SQL Programming
PL/SQL Agenda: Basic PL/SQL block structure
Programming in Oracle with PL/SQL
Introduction to PL/SQL
Exception Handling in PL/SQL. POINTS TO DISCUSS What is Exception Handling Structure of Exception Handling Section Types of Exceptions.
PL/SQL block has the following structure: DECLARE Declaration statements BEGIN Executable statements EXCEPTION Exception-handling statements END ;
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Cursor and Exception Handling By Nidhi Bhatnagar.
1 Introduction to PL/SQL. 2  Procedural programming language  Uses detailed instructions  Processes statements sequentially  Combines SQL commands.
Oracle10g Developer: PL/SQL Programming1 Objectives Manipulating data with cursors Managing errors with exception handlers Addressing exception-handling.
Chapter 4 Cursors and Exception Handling Oracle10g Developer:
Exceptions Oracle Database PL/SQL 10g Programming Chapter 7.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
EE Copyright س Oracle Corporation, All rights reserved. ® Review of PL/SQL.
INTRODUCTION TO PL/SQL. Class Agenda Introduction Introduction to PL/SQL Declaring PL/SQL Variable Creating the Executable Section Interacting with the.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Program with PL/SQL. Interacting with the Oracle Server.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
L/O/G/O Working with Composite Data Types. Objectives After completing this lesson, you should be able to do the following: –Create user-defined PL/SQL.
CS178 Database Management PL/SQL session 8 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman.
CSIT 313 DB PROGRAMMING EXCEPTION HANDLING. In PL/SQL, an error condition is called an exception. An exception can be either –internally defined (by the.
Oracle PL/SQL. PL/SQL Originally modeled after ADA Originally modeled after ADA Created for Dept. of DefenseCreated for Dept. of Defense Allows expanded.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Trapping Oracle Server Exceptions. 2 home back first prev next last What Will I Learn? Describe and provide an example of an error defined by the Oracle.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Chapter 15 Introduction to PL/SQL. Chapter Objectives  Explain the benefits of using PL/SQL blocks versus several SQL statements  Identify the sections.
Database Management COP4540, SCS, FIU Oracle PL/SQL (Ch 10.5)
Handling Exceptions. 2 home back first prev next last What Will I Learn? Describe several advantages of including exception handling code in PL/SQL Describe.
Oracle 8i Exception Handling. General Syntax DECLARE --- BEGIN --- EXCEPTION WHEN exception_name1 THEN -Error handling statements WHEN exception_name2.
Using SQL in PL/SQL ITEC 224 Database Programming.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
ITEC 224 Database Programming PL/SQL Lab Cursors.
1 Handling Exceptions Part F. 2 Handling Exceptions with PL/SQL What is an exception? Identifier in PL/SQL that is raised during execution What is an.
Introduction to Explicit Cursors. 2 home back first prev next last What Will I Learn? Distinguish between an implicit and an explicit cursor Describe.
Cursor FOR Loops. 2 home back first prev next last What Will I Learn? List and explain the benefits of using cursor FOR loops Create PL/SQL code to declare.
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Stored Procedure used in PosgreSQL.
implicit and an explicit cursor
Chapter 18: Exception Handling1 Chapter Eighteen Exception Handling Objective: – Define exceptions – List types of exception handlers – Trap errors – Exception.
1 ITBIS373 Database Development Lecture 2 – Chapter 4B Introduction to PL/SQL.
Handling Exceptions. Objectives What is exception Types of exceptions How to handle exceptions Trapping pre defined oracle errors.
Copyright  Oracle Corporation, All rights reserved. 23 Handling Exceptions.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
DB Programming Course Lecture 4. Errors Two types of errors can be found in a program: compilation errors and runtime errors. There is a special section.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
ITEC 224 Database Programming
CHAPTER 5 EXCEPTION HANDLING
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
DataBase Logic in Business Applications
Interacting with the Oracle Server
PL/SQL.
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Cursors ITEC 224 Database Programming PL/SQL Lab.
Oracle9i Developer: PL/SQL Programming Chapter 3 PL/SQL Processing.
Handling Exceptions.
Database Programming PL SQL.
Database Management Systems 2
Handling Exceptions.
Stored Procedure used in PosgreSQL
Handling Exceptions.
Chapter 2 Handling Data in PL/SQL Blocks Oracle9i Developer:
Database Management Systems 2
Handling Exceptions.
Chapter 8 Advanced SQL.
PL/SQL Declaring Variables.
Presentation transcript:

Chapter 16 Cursors and Exceptions

Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor  Fetch data from an explicit cursor  Identify attributes associated with a cursor  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor  Fetch data from an explicit cursor  Identify attributes associated with a cursor

Chapter Objectives  Use a cursor FOR loop to retrieve data from a cursor  Declare a cursor in the subquery of a cursor FOR loop  Evaluate BOOLEAN conditions combined with logical operators  Identify the purpose of the exception- handling section of a PL/SQL block  Use a cursor FOR loop to retrieve data from a cursor  Declare a cursor in the subquery of a cursor FOR loop  Evaluate BOOLEAN conditions combined with logical operators  Identify the purpose of the exception- handling section of a PL/SQL block

Chapter Objectives  Trap predefined exceptions in a PL/SQL block  Trap user-defined exceptions in a PL/SQL block  Trap predefined exceptions in a PL/SQL block  Trap user-defined exceptions in a PL/SQL block

Cursor  An area in memory that holds the values currently being processed  Must be explicitly declared when retrieving more than one row  An area in memory that holds the values currently being processed  Must be explicitly declared when retrieving more than one row

Opening an Explicit Cursor When opened, the memory is allocated, the SELECT statement is executed, and necessary data is loaded into the cursor

Closing the Cursor

Fetching Data from the Cursor  Data is retrieved from an explicit cursor using the FETCH command  Assigns the values to previously declared variables  Data is retrieved from an explicit cursor using the FETCH command  Assigns the values to previously declared variables

Cursor Attributes

Cursor Example Declaring a cursor Opening a cursor Fetching data Closing a cursor

Cursor FOR Loop Automatically opens and closes a cursor, and fetchs data from a cursor

Example Cursor FOR Loop

%ROWTYPE Attribute Specifies that a record will have the same structure as the row being retrieved

Logic Table Determines how a statement will be evaluated when conditions are joined with logical operators

Exception Handling  Exception – signal that an error has occurred  Does not include syntax errors  Common examples – NO_DATA_FOUND, TOO_MANY_ROWS, ZERO_DIVIDE  Exception – signal that an error has occurred  Does not include syntax errors  Common examples – NO_DATA_FOUND, TOO_MANY_ROWS, ZERO_DIVIDE

Exception-Handling Section Syntax

Exception Example

User-Defined Exception Handling  Name of exception must be declared with datatype EXCEPTION  Declared exception must be associated with Oracle server error number using PRAGMA EXCEPTION_INIT statement  Must be included in the block’s exception-handling section  Name of exception must be declared with datatype EXCEPTION  Declared exception must be associated with Oracle server error number using PRAGMA EXCEPTION_INIT statement  Must be included in the block’s exception-handling section

Syntax for the PRAGMA EXCEPTION_INIT Statement

Example of Trapping a User-Defined Exception