SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Prepared By JAVATECH “Search us in The World”
1
EXCEPTION HANDLING IN PLSQL
What is exception ?
Exceptions are abnormal condition that can be occur during the execution of
program.
Exceptions are used to handled run-time errors in PLSQL. And to handled
that exception PLSQL specified exception block is called Exception Block.
E.g.
Prepared By JAVATECH “Search us in The World”
2
Exceptions are two types
1. System Defined Exception
2. User Defined Exception
System Defined Exception
System Defined Exceptions are defined by Oracle Server. This exceptions
contains some predefined error numbers with predefined error messages.
These numbers and messages are
SYSTEM_EXCEPTION ERROR_NO DESCRIPTION
NO_DATA_FOUND ORA-01403 QUERY RETURN NO DATA
INVALID_CURSOR ORA-01001 ILLEGAL CURSOR OPERATION OCCURRED IN PROGRAM
CURSOR_ALREADY_OPEN ORA-06511 TRY TO OPEN “ALREADY OPENED CURSOR”
INVALID_NUMBER ORA-01722 FAILED TO CONVERT FROM CHARACTER TO NUMBER
ZERO_DIVIDE ORA-01476 ATTEMT TO DIVIDE BY ZERO (ARITHMETICEXCEPTION IN JAVA)
Prepared By JAVATECH “Search us in The World”
User defined Exception
This exception is defined by user. You declare identifier with exception
datatype. And it will de declare in declare section. And raised it inside the
begin block. And if exception generated then control will automatically
transferred to exception block. And exception message will displayed. There
are some exception which are generated in our program but system is not
defined. To control that exception we use user defined exceptions
Prepared By JAVATECH “Search us in The World”
3
EXCEPTION STRUCTURE
Above diagram In User Defined Exception we use Raise keyword to send
exception to specified identifier.
Description
1. Declare part is used to declare variable, Exception Variable &
Constants.
2. My_Exec is a variable which is defined Exception type. When
exception will generate then My_Exce part will be executed. In java
we write class My_Exec extends Exception to create user defined
exception.
3. Between begin & Exception part your exception will be generate. So if
you think exception may be occur then use raise keyword and give the
exception variable name. Just I wrote Raise My_Exec.
4. Define that exception with error message. You will write
Prepared By JAVATECH “Search us in The World”
4
when My_Exec then
dbms_output.put_line(‘Your own error message’);
end;
Now I will first show you one by one system defined exception then I will
go to user defined exception.
My_Table name STD99;
NO_DATA_FOUND Exception
Wap in PLSQL to display the row whose roll no is 9. Means roll 9 doesn’t
exist then here NO_DATA_FOUND exception will generate.
Prepared By JAVATECH “Search us in The World”
5
INVALID_CURSOR Exception program
It is occurred in three conditions.
Actually rules of cursor is
1. Declare
2. Open
3. Fetch
4. Close
When it will be invalid_cursor (If you perform invalid cursor operation)
If fetch before opening cursor (I have done in my example. I first fetch
then open cursor. It is wrong. Without open cursor how you will fetch
first.)
You closed cursor before open
You fetched cursor after closing cursor.
Prepared By JAVATECH “Search us in The World”
6
CURSOR_ALREADY_OPENED Exception program.
It is generated if you try to open cursor which is previously already opened.
INVALID_NUMBER in java it is called NumberFormatException. It is
generated when you try to insert string data in numeric column in databse.
If string data is numeric type then oracle server implicit convert it.
Otherwise raise INVALID_NUMBER Exception.
Prepared By JAVATECH “Search us in The World”
7
See Example.
ZERO_DIVIDE Exception ( in java is called ArithmeticException )
When you try to divide any number by zero it generates ZERO_DIVIDE
exception.
Watch example…..
Prepared By JAVATECH “Search us in The World”
8
Now I will discuss user defined exception
Previous program system automatically know number is divide by zero in
z:=x/y line. But user defined exception we check if y enter number is equal
to zero then we explicitly generate exception by using raise keyword. And in
raise keyword we specify exception identifier name.
E.g
MyExec Exception; here MyExec is a identifier which is declared Exception
type. And we check y is zero or not if zero raise MyExec
If y=0 then
Raise MyExec;
And in Exception block previously we specified ZERO_DIVIDE system defined
Exception. But here we use our defined as “MyExec” see how…
When ZERO_DIVIDE then
Dbms_output.put_line(‘Divide by zero is not possible’);
End
But User defined we write
When MyExec then
Dbms_output.put_line(‘Divide by zero is not possible’);
End;
Prepared By JAVATECH “Search us in The World”
9
See Exmple…..
RAISE_APPLICATION_ERROR
Is there any technique without define exception block we can specify our
user defined error message with our own error no. Yes there is technique
called RAISE_APPLICATION_ERROR(erro_no,err_message)
Error_no range should be -20,000 to -20,999 [ give the - minus symbol ]
Message upto 2048 byte long
Where to specify it. You will write in begin section directly with errno and
err message. Generally it is defined in your user defined exception. After use
Prepared By JAVATECH “Search us in The World”
10
raise_application_error your program is terminated there. No further
executed.
See Examples….. with zero divide exception
FIND MORE SEARCH US IN FACEBOOK “JAVATECH 123”
***********Thanking You.************

More Related Content

PDF
PL/SQL TRIGGERS
PPTX
PPT
04 Handling Exceptions
PPT
Abstract class in java
PDF
Triggers in SQL | Edureka
PPTX
SQL - DML and DDL Commands
PPT
10 Creating Triggers
PL/SQL TRIGGERS
04 Handling Exceptions
Abstract class in java
Triggers in SQL | Edureka
SQL - DML and DDL Commands
10 Creating Triggers

What's hot (20)

PPT
PPTX
SQL Queries Information
PPTX
Packages in PL/SQL
PPTX
Database Connectivity in PHP
PPTX
Sql Constraints
PPTX
Constructor and Types of Constructors
PPTX
PPTX
Unit 4 plsql
PDF
Java threads
PPTX
Dynamic method dispatch
PPTX
Sql clauses by Manan Pasricha
PPTX
INHERITANCE IN JAVA.pptx
PPTX
4. plsql
PPTX
Interface in java
PPTX
Nested queries in database
PPTX
Constructor overloading & method overloading
PPTX
database language ppt.pptx
PPTX
Super keyword in java
SQL Queries Information
Packages in PL/SQL
Database Connectivity in PHP
Sql Constraints
Constructor and Types of Constructors
Unit 4 plsql
Java threads
Dynamic method dispatch
Sql clauses by Manan Pasricha
INHERITANCE IN JAVA.pptx
4. plsql
Interface in java
Nested queries in database
Constructor overloading & method overloading
database language ppt.pptx
Super keyword in java
Ad

Similar to Exception handling in plsql (20)

PDF
Exception Handling
PPTX
Different Kinds of Exception in DBMS
PDF
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
PPT
Errors and exception
PPT
Java Exception Handling & IO-Unit-3 (1).ppt
PPTX
Java Exceptions and Exception Handling
PPTX
Exception handling
PPT
Exception handling
PPTX
Chapter 5
PPT
Oracle PL/SQL exception handling
PPTX
JAVA Presenttation topics Programs.pptx
PPTX
Exception handling in java
PPTX
Exceptions in java
PPTX
L14 exception handling
PPT
Exception Handling in java masters of computer application
PPTX
PL/SQL & SQL CODING GUIDELINES – Part 7
PPTX
7. exceptions handling in pl
PPTX
Exception handling in java
PPT
9781111530532 ppt ch11
Exception Handling
Different Kinds of Exception in DBMS
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
Errors and exception
Java Exception Handling & IO-Unit-3 (1).ppt
Java Exceptions and Exception Handling
Exception handling
Exception handling
Chapter 5
Oracle PL/SQL exception handling
JAVA Presenttation topics Programs.pptx
Exception handling in java
Exceptions in java
L14 exception handling
Exception Handling in java masters of computer application
PL/SQL & SQL CODING GUIDELINES – Part 7
7. exceptions handling in pl
Exception handling in java
9781111530532 ppt ch11
Ad

More from Arun Sial (6)

PDF
Triggers in plsql
PDF
PLSQL CURSOR
PDF
Procedure and Function in PLSQL
PDF
PLSQL Note
PDF
SQL BUILT-IN FUNCTION
DOCX
Database object, sub query, Join Commands & Lab Assignment
Triggers in plsql
PLSQL CURSOR
Procedure and Function in PLSQL
PLSQL Note
SQL BUILT-IN FUNCTION
Database object, sub query, Join Commands & Lab Assignment

Recently uploaded (20)

PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Nekopoi APK 2025 free lastest update
PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Introduction to Artificial Intelligence
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Digital Strategies for Manufacturing Companies
Reimagine Home Health with the Power of Agentic AI​
wealthsignaloriginal-com-DS-text-... (1).pdf
Digital Systems & Binary Numbers (comprehensive )
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Design an Analysis of Algorithms I-SECS-1021-03
Softaken Excel to vCard Converter Software.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Nekopoi APK 2025 free lastest update
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
Odoo Companies in India – Driving Business Transformation.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Strategies for Manufacturing Companies

Exception handling in plsql

  • 1. Prepared By JAVATECH “Search us in The World” 1 EXCEPTION HANDLING IN PLSQL What is exception ? Exceptions are abnormal condition that can be occur during the execution of program. Exceptions are used to handled run-time errors in PLSQL. And to handled that exception PLSQL specified exception block is called Exception Block. E.g.
  • 2. Prepared By JAVATECH “Search us in The World” 2 Exceptions are two types 1. System Defined Exception 2. User Defined Exception System Defined Exception System Defined Exceptions are defined by Oracle Server. This exceptions contains some predefined error numbers with predefined error messages. These numbers and messages are SYSTEM_EXCEPTION ERROR_NO DESCRIPTION NO_DATA_FOUND ORA-01403 QUERY RETURN NO DATA INVALID_CURSOR ORA-01001 ILLEGAL CURSOR OPERATION OCCURRED IN PROGRAM CURSOR_ALREADY_OPEN ORA-06511 TRY TO OPEN “ALREADY OPENED CURSOR” INVALID_NUMBER ORA-01722 FAILED TO CONVERT FROM CHARACTER TO NUMBER ZERO_DIVIDE ORA-01476 ATTEMT TO DIVIDE BY ZERO (ARITHMETICEXCEPTION IN JAVA) Prepared By JAVATECH “Search us in The World” User defined Exception This exception is defined by user. You declare identifier with exception datatype. And it will de declare in declare section. And raised it inside the begin block. And if exception generated then control will automatically transferred to exception block. And exception message will displayed. There are some exception which are generated in our program but system is not defined. To control that exception we use user defined exceptions
  • 3. Prepared By JAVATECH “Search us in The World” 3 EXCEPTION STRUCTURE Above diagram In User Defined Exception we use Raise keyword to send exception to specified identifier. Description 1. Declare part is used to declare variable, Exception Variable & Constants. 2. My_Exec is a variable which is defined Exception type. When exception will generate then My_Exce part will be executed. In java we write class My_Exec extends Exception to create user defined exception. 3. Between begin & Exception part your exception will be generate. So if you think exception may be occur then use raise keyword and give the exception variable name. Just I wrote Raise My_Exec. 4. Define that exception with error message. You will write
  • 4. Prepared By JAVATECH “Search us in The World” 4 when My_Exec then dbms_output.put_line(‘Your own error message’); end; Now I will first show you one by one system defined exception then I will go to user defined exception. My_Table name STD99; NO_DATA_FOUND Exception Wap in PLSQL to display the row whose roll no is 9. Means roll 9 doesn’t exist then here NO_DATA_FOUND exception will generate.
  • 5. Prepared By JAVATECH “Search us in The World” 5 INVALID_CURSOR Exception program It is occurred in three conditions. Actually rules of cursor is 1. Declare 2. Open 3. Fetch 4. Close When it will be invalid_cursor (If you perform invalid cursor operation) If fetch before opening cursor (I have done in my example. I first fetch then open cursor. It is wrong. Without open cursor how you will fetch first.) You closed cursor before open You fetched cursor after closing cursor.
  • 6. Prepared By JAVATECH “Search us in The World” 6 CURSOR_ALREADY_OPENED Exception program. It is generated if you try to open cursor which is previously already opened. INVALID_NUMBER in java it is called NumberFormatException. It is generated when you try to insert string data in numeric column in databse. If string data is numeric type then oracle server implicit convert it. Otherwise raise INVALID_NUMBER Exception.
  • 7. Prepared By JAVATECH “Search us in The World” 7 See Example. ZERO_DIVIDE Exception ( in java is called ArithmeticException ) When you try to divide any number by zero it generates ZERO_DIVIDE exception. Watch example…..
  • 8. Prepared By JAVATECH “Search us in The World” 8 Now I will discuss user defined exception Previous program system automatically know number is divide by zero in z:=x/y line. But user defined exception we check if y enter number is equal to zero then we explicitly generate exception by using raise keyword. And in raise keyword we specify exception identifier name. E.g MyExec Exception; here MyExec is a identifier which is declared Exception type. And we check y is zero or not if zero raise MyExec If y=0 then Raise MyExec; And in Exception block previously we specified ZERO_DIVIDE system defined Exception. But here we use our defined as “MyExec” see how… When ZERO_DIVIDE then Dbms_output.put_line(‘Divide by zero is not possible’); End But User defined we write When MyExec then Dbms_output.put_line(‘Divide by zero is not possible’); End;
  • 9. Prepared By JAVATECH “Search us in The World” 9 See Exmple….. RAISE_APPLICATION_ERROR Is there any technique without define exception block we can specify our user defined error message with our own error no. Yes there is technique called RAISE_APPLICATION_ERROR(erro_no,err_message) Error_no range should be -20,000 to -20,999 [ give the - minus symbol ] Message upto 2048 byte long Where to specify it. You will write in begin section directly with errno and err message. Generally it is defined in your user defined exception. After use
  • 10. Prepared By JAVATECH “Search us in The World” 10 raise_application_error your program is terminated there. No further executed. See Examples….. with zero divide exception FIND MORE SEARCH US IN FACEBOOK “JAVATECH 123” ***********Thanking You.************