SlideShare a Scribd company logo
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

What's hot

ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
ASHABOOPATHY
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
Umair Shakir
 
Methods in java
Methods in javaMethods in java
Methods in java
chauhankapil
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
Hitesh Kumar
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
garishma bhatia
 
Different Kinds of Exception in DBMS
Different Kinds of Exception in DBMSDifferent Kinds of Exception in DBMS
Different Kinds of Exception in DBMS
Suja Ritha
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread SynchronizationBenj Del Mundo
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
farwa waqar
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
Bharat Kalia
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
Raveena Thakur
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
lalithambiga kamaraj
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
SURIT DATTA
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Java package
Java packageJava package
Java package
CS_GDRCST
 

What's hot (20)

JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
 
Methods in java
Methods in javaMethods in java
Methods in java
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
 
Different Kinds of Exception in DBMS
Different Kinds of Exception in DBMSDifferent Kinds of Exception in DBMS
Different Kinds of Exception in DBMS
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Java package
Java packageJava package
Java package
 

Similar to Exception handling in plsql

Exception Handling
Exception Handling Exception Handling
Exception Handling
Swapnali Pawar
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
OCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 ExceptionsOCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 Exceptions
İbrahim Kürce
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
poongothai11
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
pooja kumari
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
Ashwin Shiv
 
Introduction to Exception
Introduction to ExceptionIntroduction to Exception
Introduction to Exception
Swabhav Techlabs
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
DrRajeshreeKhande
 
Java Exceptions
Java ExceptionsJava Exceptions
Java Exceptions
jalinder123
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertionsphanleson
 
Java -Exception handlingunit-iv
Java -Exception handlingunit-ivJava -Exception handlingunit-iv
Java -Exception handlingunit-iv
RubaNagarajan
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
Ankit Rai
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
Abinaya B
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
Kuntal Bhowmick
 
Exception handling
Exception handlingException handling
Exception handling
Karthik Sekar
 
VTU MCA 2022 JAVA Exceeption Handling.docx
VTU MCA  2022 JAVA Exceeption Handling.docxVTU MCA  2022 JAVA Exceeption Handling.docx
VTU MCA 2022 JAVA Exceeption Handling.docx
Poornima E.G.
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
primevideos176
 

Similar to Exception handling in plsql (20)

Exception Handling
Exception Handling Exception Handling
Exception Handling
 
Java exception
Java exception Java exception
Java exception
 
OCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 ExceptionsOCA Java SE 8 Exam Chapter 6 Exceptions
OCA Java SE 8 Exam Chapter 6 Exceptions
 
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Java SE 11 Exception Handling
Java SE 11 Exception HandlingJava SE 11 Exception Handling
Java SE 11 Exception Handling
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
Introduction to Exception
Introduction to ExceptionIntroduction to Exception
Introduction to Exception
 
Java Exceptions Handling
Java Exceptions Handling Java Exceptions Handling
Java Exceptions Handling
 
Java Exceptions
Java ExceptionsJava Exceptions
Java Exceptions
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Itp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & AssertionsItp 120 Chapt 18 2009 Exceptions & Assertions
Itp 120 Chapt 18 2009 Exceptions & Assertions
 
Java -Exception handlingunit-iv
Java -Exception handlingunit-ivJava -Exception handlingunit-iv
Java -Exception handlingunit-iv
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
Class notes(week 8) on exception handling
Class notes(week 8) on exception handlingClass notes(week 8) on exception handling
Class notes(week 8) on exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
VTU MCA 2022 JAVA Exceeption Handling.docx
VTU MCA  2022 JAVA Exceeption Handling.docxVTU MCA  2022 JAVA Exceeption Handling.docx
VTU MCA 2022 JAVA Exceeption Handling.docx
 
Exception Handling.pptx
Exception Handling.pptxException Handling.pptx
Exception Handling.pptx
 

More from Arun Sial

Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
Arun Sial
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
Arun Sial
 
Procedure and Function in PLSQL
Procedure and Function in PLSQLProcedure and Function in PLSQL
Procedure and Function in PLSQL
Arun Sial
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
Arun Sial
 
SQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTIONSQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTION
Arun Sial
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
Arun Sial
 

More from Arun Sial (6)

Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
 
Procedure and Function in PLSQL
Procedure and Function in PLSQLProcedure and Function in PLSQL
Procedure and Function in PLSQL
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
 
SQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTIONSQL BUILT-IN FUNCTION
SQL BUILT-IN FUNCTION
 
Database object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab AssignmentDatabase object, sub query, Join Commands & Lab Assignment
Database object, sub query, Join Commands & Lab Assignment
 

Recently uploaded

Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 

Recently uploaded (20)

Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 

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.************