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.

Slides:



Advertisements
Similar presentations
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
Advertisements

1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
PL/SQL (Procedural Language extensions to SQL) Prepared by: Manoj Kathpalia Edited by: M V Ramakrishna.
Chapter 4B: More Advanced PL/SQL Programming
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Spring 2005 Chapter 8  Errors and Exceptions Throwable class.
Handling Errors with Exception (in Java) Project 10 CSC 420.
1 Agenda Summary of last class Loops Simple Loops WHILE Loops FOR Loops Records Cursors.
PL/SQL block has the following structure: DECLARE Declaration statements BEGIN Executable statements EXCEPTION Exception-handling statements END ;
Bordoloi and Bock PL/SQL : INTRODUCTION. Bordoloi and BockPL/SQL PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational.
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
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.
Bordoloi and Bock EXCEPTIONS. Bordoloi and Bock Errors Two types of errors can be found in a program: compilation errors and runtime errors. There is.
Cursor and Exception Handling By Nidhi Bhatnagar.
Exceptions Oracle Database PL/SQL 10g Programming Chapter 7.
CIS 270—Application Development II Chapter 13—Exception Handling.
Benefits of PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –List and explain the benefits of PL/SQL –List.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Oracle10g Developer: PL/SQL Programming1 Objectives Programming fundamentals The PL/SQL block Define and declare variables Initialize variables The NOT.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
PL/SQL : INTRODUCTION. PL/SQL PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database language. With PL/SQL, you.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
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.
PL / SQL By Mohammed Baihan. What is PL/SQL? PL/SQL stands for Procedural Language extension of SQL. PL/SQL is a combination of SQL along with the procedural.
PL/SQL Oracle's Database Programming Language. Remember: Set serveroutput on With serveroutput off (default) executing procedure: With serveroutput on:
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
CIS4368: Advanced DatabaseSlide # 1 PL/SQL Dr. Peeter KirsSpring, 2003 PL/SQL.
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.
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.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
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.
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.
Chapter 16 Cursors and Exceptions. Chapter Objectives  Determine when an explicit cursor is required  Declare, open, and close an explicit cursor 
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
implicit and an explicit cursor
Chapter 18: Exception Handling1 Chapter Eighteen Exception Handling Objective: – Define exceptions – List types of exception handlers – Trap errors – Exception.
Handling Exceptions. Objectives What is exception Types of exceptions How to handle exceptions Trapping pre defined oracle errors.
PRACTICE OVERVIEW PL/SQL Part Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
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.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
Exception. Agenda Exception. Handling Exceptions. The finally Clause.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
CS422 Principles of Database Systems Oracle PL/SQL Chengyu Sun California State University, Los Angeles.
Lecture 18B Exception Handling and Richard Gesick.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
Free Powerpoint Templates Page 1 Free Powerpoint Templatesبسم الله الرحمن الرحيم عدد الساعات: 2 نظري+2عملي الرمز:314 حسب المتطلبات:223 حسب (مبادئ قواعد.
ITEC 224 Database Programming
Java Exceptions a quick review….
CHAPTER 5 EXCEPTION HANDLING
Handling Exceptions.
Oracle11g: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
Oracle9i Developer: PL/SQL Programming Chapter 3 PL/SQL Processing.
Handling Exceptions.
Database Programming PL SQL.
Agenda Summary of last class Cursors Loops Records Simple Loops
PL/SQL Scripting in Oracle:
Advanced PL/SQL Programing
Handling Exceptions.
Handling Exceptions.
Database Management Systems 2
Handling Exceptions.
Programming in C# CHAPTER - 7
Exception Handling.
Database Programming Using Oracle 11g
Presentation transcript:

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 in a PL/SQL block that handles the runtime errors. This section is called the exception-handling section, and in it, runtime errors are referred to as exceptions. The exception-handling section allows programmers to specify what actions should be taken when a specific exception occurs.

Exception Handling In order to handle run time errors in the program, an exception handler must be added. The exception-handling section has the following structure:  EXCEPTION  WHEN EXCEPTION_NAME  THEN  ERROR-PROCESSING STATEMENTS;

Exception Handling In addition, an exception-handling section allows a program to execute to completion, instead of terminating prematurely. Another advantage offered by the exception- handling section is isolation of error-handling routines. In other words, all error-processing code for a specific block is located in the single section. As a result, the logic of the program becomes easier to follow and understand.

Some Predefined PL/SQL Exceptions

Using Exception Handler

Notes To continue execution from the spot where an exception occurred, enclose the code that might raise an exception inside another BEGIN-END block with its own exception handler. For example, put separate BEGIN-END blocks around groups of SQL statements that might raiseNO_DATA_FOUND, or around arithmetic operations that might raise DIVIDE_BY_ZERO. By putting a BEGIN-END block with an exception handler inside of a loop, you can continue executing the loop if some loop iterations raise exceptions.

Continuing After an Exception in PL/SQL

Example DECLARE v_student_name VARCHAR2(50); BEGIN SELECT first_name||‘ ’||last_name INTO v_student_name FROM student WHERE student_id = 101; DBMS_OUTPUT.PUT_LINE (‘Student name is’||v_student_name); EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE (‘There is no such student’); END;

Example DECLARE v_student_id NUMBER := &sv_student_id; v_enrolled VARCHAR2(3) := 'NO'; BEGIN DBMS_OUTPUT.PUT_LINE (‘Check if the student is enrolled’); SELECT ‘YES’ INTO v_enrolled FROM enrollment WHERE student_id = v_student_id; DBMS_OUTPUT.PUT_LINE (‘The student is enrolled into one course’); EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE(‘The student is not enrolled’); WHEN TOO_MANY_ROWS THEN DBMS_OUTPUT.PUT_LINE (‘The student is enrolled into many courses’); END;