Database Programming Using Oracle 11g

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Triggers The different types of integrity constraints discussed so far provide a declarative mechanism to associate “simple” conditions with a table such.
Chapter 4B: More Advanced PL/SQL Programming
PL/SQL Agenda: Basic PL/SQL block structure
Exception types In Oracle PL/SQL. Types of exceptions Named system exceptions –Raised as a result of an error in PL/SQL or RDBMS processing. Named programmer-defined.
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 ;
Introduction to PL/SQL. Procedural Language extension for SQL Oracle Proprietary 3GL Capabilities Integration of SQL Portable within Oracle data bases.
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.
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.
EE Copyright س Oracle Corporation, All rights reserved. ® Review of PL/SQL.
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
In Oracle.  A PL/SQL block stored in the database and fired in response to a specified event ◦ DML statements : insert, update, delete ◦ DDL statements.
Matthew P. Johnson, OCL3, CISDD CUNY, June OCL3 Oracle 10g: SQL & PL/SQL Session #8 Matthew P. Johnson CISDD, CUNY June, 2004.
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.
1 CursorsCursors. 2 SQL Cursor A cursor is a private SQL work area. A cursor is a private SQL work area. There are two types of cursors: There are two.
PL/SQL Oracle's Database Programming Language. Remember: Set serveroutput on With serveroutput off (default) executing procedure: With serveroutput on:
Oracle PL/SQL. PL/SQL Originally modeled after ADA Originally modeled after ADA Created for Dept. of DefenseCreated for Dept. of Defense Allows expanded.
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.
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.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Anonymous Block · Types of Block · Declaring a Variable · Constant.
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.
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 
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
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.
Introduction to PL/SQL As usual, use speaker notes for additional information!
Oracle10g Developer: PL/SQL Programming1 Objectives Named program units How to identify parameters The CREATE PROCEDURE statement Creating a procedure.
Copyright  Oracle Corporation, All rights reserved. 23 Handling Exceptions.
Introduction to PL/SQL N. Dimililer. About PL/SQL –PL/SQL is an extension to SQL with design features of programming languages. –Data manipulation and.
Oracle 数据库应用 -- PL/SQL 进阶 (3) & Oracle DBA 2016/5/ /5/10.
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.
Free Powerpoint Templates Page 1 Free Powerpoint Templatesبسم الله الرحمن الرحيم عدد الساعات: 2 نظري+2عملي الرمز:314 حسب المتطلبات:223 حسب (مبادئ قواعد.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
ITEC 224 Database Programming
CHAPTER 5 EXCEPTION HANDLING
Oracle11g: PL/SQL Programming Chapter 5 Procedures.
DataBase Logic in Business Applications
Handling Exceptions.
SQL Stored Triggers Presented by: Dr. Samir Tartir
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Oracle9i Developer: PL/SQL Programming Chapter 3 PL/SQL Processing.
Handling Exceptions.
Database Programming PL SQL.
SQL PL/SQL Presented by: Dr. Samir Tartir
PL/SQL Scripting in Oracle:
Advanced PL/SQL Programing
Handling Exceptions.
Handling Exceptions.
Database Management Systems 2
Handling Exceptions.
PL/SQL Declaring Variables.
Exception Handling.
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Database Programming Using Oracle 11g
Copyright All material contained herein is owned by Daniel Stober, the author of this presentation. This presentation and the queries, examples, and original.
Presentation transcript:

Database Programming Using Oracle 11g Error Handling and Exceptions

Error Handling and Exceptions Error Handling and Exception: Exception vs Error Compile time syntax issues are Error Run-time errors are usually Exceptions. Semantic error are exceptions

Error Handling and Exceptions Need for Exception Handling It is practically not possible to foresee all problematic events Exception cause the program to terminate abnormally

Error Handling and Exceptions Need for Exception Handling Flow of program is broken and control is lost from developer view point Even the best programmer can have bugs in code

Error Handling and Exceptions Handling Exceptions Special block in PL/SQL to handle exceptions. Run-time error can be handled to avoid abnormal termination of program

Error Handling and Exceptions How Exception Handling Work When run-time error is generated Exception is raised. Current flow stop. Control is transferred to Exception block of PL/SQL

Error Handling and Exceptions Type of Exceptions Internal Internal exceptions are define Raised automatically

Error Handling and Exceptions Type of Exceptions User Define User should define it User should raise the exception

Error Handling and Exceptions Formation of Built – in Exception Three component Exception Name Exception unique number Description

Error Handling and Exceptions DUP_VAL_ON_INDEX ORA-00001 Exception raised when you store duplicate value in unique constraint column. CASE_NOT_FOUND ORA-06592 Exception raised when no any choice case found in CASE statement as well as no ELSE clause in CASE statement.

Error Handling and Exceptions Formation of Exception Build – in Exceptions unique numbers are system generated

Error Handling and Exceptions Syntax of Exception

Error Handling and Exceptions Declare Section All the declarations Begin Executable statements Exception Section – One per block Exception handling statements End;

Error Handling and Exceptions Syntax of Exception One Exception section per block Nested blocks can have separate exception section

Error Handling and Exceptions Scope of Exception

Error Handling and Exceptions Declare Section All the declarations Begin Executable statements Exception handling statements declare – Inner block begin exception – local to innerblock End; Exception Section – Global exception end;

Error Handling and Exceptions Implementing Build-In Exception -I

Error Handling and Exceptions DECLARE stock_price NUMBER := 9.73; net_earnings NUMBER := 0; pe_ratio NUMBER; BEGIN pe_ratio := stock_price / net_earnings; DBMS_OUTPUT.PUT_LINE('Price/earnings ratio = ' || pe_ratio);

Error Handling and Exceptions WHEN ZERO_DIVIDE THEN DBMS_OUTPUT.PUT_LINE('Company must have had zero earnings.'); pe_ratio := NULL; WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Some other kind of error occurred.'); END;

Error Handling and Exceptions Implementing Build-In Exception -II

Error Handling and Exceptions declare grade varchar2(1):='H'; begin CASE WHEN grade = 'A' THEN dbms_output.put_line('Excellent'); WHEN grade = 'B' THEN dbms_output.put_line('Very Good'); WHEN grade = ‘C' THEN dbms_output.put_line('Fair');

Error Handling and Exceptions WHEN grade = ‘D' THEN dbms_output.put_line('Poor'); END CASE; exception When case_not_found then dbms_output.put_line(‘No Case match'); When others then dbms_output.put_line ('In the exception block‘ || SQLERRM || SQLCode); end;

Error Handling and Exceptions Implementing Built-In Exception and SQL-III

Error Handling and Exceptions declare name varchar2(30):=''; begin select ename into name from emp; exception when no_data_found then dbms_output.put_line('Record not matched');

Error Handling and Exceptions when DUP_VAL_ON_INDEX then dbms_output.put_line('Unique Key Violated'); when others then dbms_output.put_line(SQLCODE); dbms_output.put_line(SQLERRM); end;

Error Handling and Exceptions Implementing Nested Exceptions-I

Error Handling and Exceptions declare name varchar2(30); begin select ename into name from emp where empno=7369; dbms_output.put_line(name); insert into emp (empno) values(7369);

Error Handling and Exceptions dbms_output.put_line(name); exception when dup_val_on_index then dbms_output.put_line('Duplicated values in inner block'); when others then dbms_output.put_line('In inner block'); dbms_output.put_line(SQLCODE); end;

Error Handling and Exceptions when NO_data_found then dbms_output.put_line('No Data Found in outer Block'); when others then dbms_output.put_line('No Data found in outer block'); end;

Error Handling and Exceptions Implementing Nested Exceptions-II

Error Handling and Exceptions declare name varchar2(30); begin select ename into name from emp where empno=7369; dbms_output.put_line(name); select ename into name from emp where empno=7338;

Error Handling and Exceptions dbms_output.put_line(name); exception when INVALID_NUMBER then dbms_output.put_line(SQLCODE); end; when NO_DATA_FOUND then dbms_output.put_line('No Data found in outer block');