SlideShare a Scribd company logo
Pl/sql exception
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.
How to handle Exception
• 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;
• The exception-handling section is placed
after the executable section of the block.
How exception can be classified???
 Build-in exception
 Userdefined exception
BUILT-IN EXCEPTIONS
 When a built-in exception occurs, it is said to
be raised implicitly.
 In other words, if a program breaks an Oracle
rule, the control is passed to the exception-
handling section of the block.
 At this point, the error processing statements
are executed.
 It is important for you to realize that after the
exception-handling section of the block has
executed, the block terminates.
 Control will not return to the executable section
of this block.
This example produces the
following output:
There is no such student
PL/SQL procedure
successfully completed.
Why???
Because there is no record
in the STUDENT table with
student ID 101, the SELECT
INTO statement does not
return any rows.
As a result, control passes
to the exception-handling
section of the block, and
the error message “There is
no such student” is
displayed on the screen.
Even though there is a
DBMS_OUTPUT.PUT_LINE
statement right after the
SELECT statement, it will
not be executed because
control has been
transferred to the
exception-handling section.
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;
What are predefined exception??
 The list shown below explains some commonly used predefined
exceptions and how they are raised:
 NO_DATA_FOUND This exception is raised when a SELECT
INTO statement, which makes no calls to group functions, such
as SUM or COUNT, does not return any rows.
 For example, you issue a SELECT INTO statement against
STUDENT table where student ID equals 101.
 If there is no record in the STUDENT table passing this criteria
(student ID equals 101), the NO_DATA_FOUND exception is
raised.
TOO_MANY_ROWS
 This exception is raised when a SELECT INTO
statement returns more than one row.
 By definition, a SELECT INTO can return only single
row.
 If a SELECT INTO statement returns more than one
row, the definition of the SELECT INTO statement
is violated.
 This causes the TOO_MANY_ROWS exception to be
raised.
 For example, you issue a SELECT INTO statement
against the STUDENT table for a specific zip code.
 There is a big chance that this SELECT statement
will return more than one row because many
students can live in the same zip code area.
ZERO_DIVIDE
 This exception is raised when a division operation is
performed in the program and a divisor is equal to zero.
 Previous example in the illustrates how this exception is
raised.
LOGIN_DENIED
 This exception is raised when a user is trying to login on
to Oracle with invalid username or password.
PROGRAM_ERROR
 This exception is raised when a PL/SQL program
has an internal problem
VALUE_ERROR
 This exception is raised when conversion or size
mismatch error occurs.
 For example, you select student’s last name into a
variable that has been defined as VARCHAR2(5).
 If student’s last name contains more than five
characters, VALUE_ERROR exception is raised.
DUP_VALUE_ON_INDEX
 This exception is raised when a program tries to
store a duplicate value in the column or columns
that have a unique index defined on them.
 For example, you are trying to insert a record into
the SECTION table for the course number “25,”
section 1.
 If a record for the given course and section
numbers already exists in the SECTION table,
DUP_VAL_ON_INDEX exception is raised because
these columns have a unique index defined on
them.
Example
FROM enrollment
WHERE student_id = v_student_id;
DBMS_OUTPUT.PUT_LINE
('Student is registered for '||v_total||' course(s)');
*/inner block*/EXCEPTION
WHEN VALUE_ERROR OR INVALID_NUMBER
THEN
DBMS_OUTPUT.PUT_LINE('An error has
occurred');
END;
*/outer block */
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.PUT_LINE('There is no such student');
END;
• The inner block has structure similar to the outer block.
• It has a SELECT INTO statement and an exception
section to handle errors.
• When VALUE_ERROR or INVALID_NUMBER error occurs
in the inner block, the exception is raised.
• It is important that you realize that exceptions
VALUE_ERROR and INVALID_NUMBER have been
defined for the inner block only.
• Therefore, they can be raised in the inner block only.
• If one of these errors occurs in the outer block, this
program will be unable to terminate successfully.
User Defined Exceptions
• Often in programs you may need to handle
problems that are specific to the program you
write.
• For example, your program asks a user to enter
a value for student_id. This value is then
assigned to the variable v_student_id that is
used later in the program.
• Generally, you want a positive number for an id.
By mistake, the user enters a negative number.
• However, no error has occurred because
student_id has been defined as a number, and
the user has supplied a legitimate numeric
value.
• Therefore, you may want to implement your
own exception to handle this situation.
How to declare user-defined exception
• A user-defined exception is declared in
the declarative part of a PL/SQL block as
shown below:
DECLARE
exception_name EXCEPTION;
• Once an exception has been declared,
the executable statements associated
with this exception are specified in the
exception-handling section of the block.
• The format of the exception-handling
section is the same as for built-in
exceptions
Raising Exception
• user-defined
exception must be
raised explicitly.
• In other words, you
need to specify in
your program under
which
circumstances an
exception must be
raised as shown :
DECLARE
exception_name
EXCEPTION;
BEGIN
…
IF CONDITION
THEN
RAISE exception_name;
ELSE
…
END IF;
EXCEPTION
WHEN exception_name
THEN
ERROR-PROCESSING
STATEMENTS;
END;
example
declare
e exception;
vamt number(10);
begin
select amt into vamt from
ac_det where acno=124;
vamt:=vamt-77000;
if(vamt<2000) then
raise e;
end if;
exception
when e then
dbms_output.put_line('Minimum
balance amount conflict');
* end;
SQL> /
Declare exception if the particular data
is not found
Raise exception ‘E’
If ‘E’ is exception the it will be
displayed as
‘minimum amount conflict’
Thank you
By R.sujaritha
Ad

More Related Content

What's hot (20)

5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf5. Basic Structure of SQL Queries.pdf
5. Basic Structure of SQL Queries.pdf
Sunita Milind Dol
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Omprakash Chauhan
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
Packages in java
Packages in javaPackages in java
Packages in java
Elizabeth alexander
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
DevoAjit Gupta
 
Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)Fundamental of C Programming (Data Types)
Fundamental of C Programming (Data Types)
jimmy majumder
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Java operators
Java operatorsJava operators
Java operators
Shehrevar Davierwala
 
Lecture 01 Intro to DSA
Lecture 01 Intro to DSALecture 01 Intro to DSA
Lecture 01 Intro to DSA
Nurjahan Nipa
 
Threads in python
Threads in pythonThreads in python
Threads in python
baabtra.com - No. 1 supplier of quality freshers
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
Meghaj Mallick
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Join
JoinJoin
Join
Kanchana Rani G
 
structures in C and Union in C, enumerated datatype
structures in C and Union in C, enumerated datatypestructures in C and Union in C, enumerated datatype
structures in C and Union in C, enumerated datatype
preetikapri1
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
Arpana shree
 
MySQL Functions
MySQL FunctionsMySQL Functions
MySQL Functions
Compare Infobase Limited
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
LakshmiSamivel
 
Different types of Linked list.
Different types of Linked list.Different types of Linked list.
Different types of Linked list.
JAYANTAOJHA
 
Pointers
PointersPointers
Pointers
sarith divakar
 

Similar to Different Kinds of Exception in DBMS (20)

Introduction to PLSQL.PPT
Introduction to PLSQL.PPTIntroduction to PLSQL.PPT
Introduction to PLSQL.PPT
SujayaBiju
 
Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08
Thuan Nguyen
 
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrjPLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
KathanPatel49
 
Plsql guide 2
Plsql guide 2Plsql guide 2
Plsql guide 2
Vinay Kumar
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
GunavathyShanmuganat
 
Pl sql
Pl sqlPl sql
Pl sql
Hitesh Kumar Markam
 
a basic java programming and data type.ppt
a basic java programming and data type.ppta basic java programming and data type.ppt
a basic java programming and data type.ppt
GevitaChinnaiah
 
Subqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsSubqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactions
maxpane
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
Ashwin Kumar
 
Exception
ExceptionException
Exception
work
 
Exception
ExceptionException
Exception
work
 
CSL101_Ch1.ppt
CSL101_Ch1.pptCSL101_Ch1.ppt
CSL101_Ch1.ppt
kavitamittal18
 
CSL101_Ch1.ppt
CSL101_Ch1.pptCSL101_Ch1.ppt
CSL101_Ch1.ppt
DrPriyaChittibabu
 
CSL101_Ch1.pptx
CSL101_Ch1.pptxCSL101_Ch1.pptx
CSL101_Ch1.pptx
shivanka2
 
CSL101_Ch1.pptx
CSL101_Ch1.pptxCSL101_Ch1.pptx
CSL101_Ch1.pptx
Ashwani Kumar
 
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBBJAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
christinemaritza
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error Handling
Richard Clark
 
Mobile computing for Bsc Computer Science
Mobile computing for Bsc Computer ScienceMobile computing for Bsc Computer Science
Mobile computing for Bsc Computer Science
ReshmiGopinath4
 
Introduction to PLSQL.PPT
Introduction to PLSQL.PPTIntroduction to PLSQL.PPT
Introduction to PLSQL.PPT
SujayaBiju
 
Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08Oracle - Program with PL/SQL - Lession 08
Oracle - Program with PL/SQL - Lession 08
Thuan Nguyen
 
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrjPLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
PLSQL.pptxokokokoo9oooodjdjfjfjfjrjejrjrrjrj
KathanPatel49
 
a basic java programming and data type.ppt
a basic java programming and data type.ppta basic java programming and data type.ppt
a basic java programming and data type.ppt
GevitaChinnaiah
 
Subqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactionsSubqueries views stored procedures_triggers_transactions
Subqueries views stored procedures_triggers_transactions
maxpane
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
Ashwin Kumar
 
Exception
ExceptionException
Exception
work
 
Exception
ExceptionException
Exception
work
 
CSL101_Ch1.pptx
CSL101_Ch1.pptxCSL101_Ch1.pptx
CSL101_Ch1.pptx
shivanka2
 
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBBJAVA CLASS PPT FOR ENGINEERING STUDENTS  BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docxCharles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
Charles WilliamsCS362Unit 3 Discussion BoardStructured Query Langu.docx
christinemaritza
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error Handling
Richard Clark
 
Mobile computing for Bsc Computer Science
Mobile computing for Bsc Computer ScienceMobile computing for Bsc Computer Science
Mobile computing for Bsc Computer Science
ReshmiGopinath4
 
Ad

Recently uploaded (20)

How to avoid IT Asset Management mistakes during implementation_PDF.pdf
How to avoid IT Asset Management mistakes during implementation_PDF.pdfHow to avoid IT Asset Management mistakes during implementation_PDF.pdf
How to avoid IT Asset Management mistakes during implementation_PDF.pdf
victordsane
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Gojek Clone App for Multi-Service Business
Gojek Clone App for Multi-Service BusinessGojek Clone App for Multi-Service Business
Gojek Clone App for Multi-Service Business
XongoLab Technologies LLP
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Driving Manufacturing Excellence in the Digital Age
Driving Manufacturing Excellence in the Digital AgeDriving Manufacturing Excellence in the Digital Age
Driving Manufacturing Excellence in the Digital Age
SatishKumar2651
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation  A Smarter Way to ScaleMaximizing ROI with Odoo Staff Augmentation  A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
SatishKumar2651
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Navigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdfNavigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdf
Applitools
 
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdfProtect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
株式会社クライム
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
How to avoid IT Asset Management mistakes during implementation_PDF.pdf
How to avoid IT Asset Management mistakes during implementation_PDF.pdfHow to avoid IT Asset Management mistakes during implementation_PDF.pdf
How to avoid IT Asset Management mistakes during implementation_PDF.pdf
victordsane
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
Time Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project TechniquesTime Estimation: Expert Tips & Proven Project Techniques
Time Estimation: Expert Tips & Proven Project Techniques
Livetecs LLC
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509Orion Context Broker introduction 20250509
Orion Context Broker introduction 20250509
Fermin Galan
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Driving Manufacturing Excellence in the Digital Age
Driving Manufacturing Excellence in the Digital AgeDriving Manufacturing Excellence in the Digital Age
Driving Manufacturing Excellence in the Digital Age
SatishKumar2651
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation  A Smarter Way to ScaleMaximizing ROI with Odoo Staff Augmentation  A Smarter Way to Scale
Maximizing ROI with Odoo Staff Augmentation A Smarter Way to Scale
SatishKumar2651
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Navigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdfNavigating EAA Compliance in Testing.pdf
Navigating EAA Compliance in Testing.pdf
Applitools
 
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdfProtect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
Protect HPE VM Essentials using Veeam Agents-a50012338enw.pdf
株式会社クライム
 
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint PresentationFrom Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
From Vibe Coding to Vibe Testing - Complete PowerPoint Presentation
Shay Ginsbourg
 
Implementing promises with typescripts, step by step
Implementing promises with typescripts, step by stepImplementing promises with typescripts, step by step
Implementing promises with typescripts, step by step
Ran Wahle
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Ad

Different Kinds of Exception in DBMS

  • 2. 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.
  • 3. How to handle Exception • 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; • The exception-handling section is placed after the executable section of the block.
  • 4. How exception can be classified???  Build-in exception  Userdefined exception
  • 5. BUILT-IN EXCEPTIONS  When a built-in exception occurs, it is said to be raised implicitly.  In other words, if a program breaks an Oracle rule, the control is passed to the exception- handling section of the block.  At this point, the error processing statements are executed.  It is important for you to realize that after the exception-handling section of the block has executed, the block terminates.  Control will not return to the executable section of this block.
  • 6. This example produces the following output: There is no such student PL/SQL procedure successfully completed. Why??? Because there is no record in the STUDENT table with student ID 101, the SELECT INTO statement does not return any rows. As a result, control passes to the exception-handling section of the block, and the error message “There is no such student” is displayed on the screen. Even though there is a DBMS_OUTPUT.PUT_LINE statement right after the SELECT statement, it will not be executed because control has been transferred to the exception-handling section. 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;
  • 7. What are predefined exception??  The list shown below explains some commonly used predefined exceptions and how they are raised:  NO_DATA_FOUND This exception is raised when a SELECT INTO statement, which makes no calls to group functions, such as SUM or COUNT, does not return any rows.  For example, you issue a SELECT INTO statement against STUDENT table where student ID equals 101.  If there is no record in the STUDENT table passing this criteria (student ID equals 101), the NO_DATA_FOUND exception is raised.
  • 8. TOO_MANY_ROWS  This exception is raised when a SELECT INTO statement returns more than one row.  By definition, a SELECT INTO can return only single row.  If a SELECT INTO statement returns more than one row, the definition of the SELECT INTO statement is violated.  This causes the TOO_MANY_ROWS exception to be raised.  For example, you issue a SELECT INTO statement against the STUDENT table for a specific zip code.  There is a big chance that this SELECT statement will return more than one row because many students can live in the same zip code area.
  • 9. ZERO_DIVIDE  This exception is raised when a division operation is performed in the program and a divisor is equal to zero.  Previous example in the illustrates how this exception is raised. LOGIN_DENIED  This exception is raised when a user is trying to login on to Oracle with invalid username or password.
  • 10. PROGRAM_ERROR  This exception is raised when a PL/SQL program has an internal problem VALUE_ERROR  This exception is raised when conversion or size mismatch error occurs.  For example, you select student’s last name into a variable that has been defined as VARCHAR2(5).  If student’s last name contains more than five characters, VALUE_ERROR exception is raised.
  • 11. DUP_VALUE_ON_INDEX  This exception is raised when a program tries to store a duplicate value in the column or columns that have a unique index defined on them.  For example, you are trying to insert a record into the SECTION table for the course number “25,” section 1.  If a record for the given course and section numbers already exists in the SECTION table, DUP_VAL_ON_INDEX exception is raised because these columns have a unique index defined on them.
  • 12. Example FROM enrollment WHERE student_id = v_student_id; DBMS_OUTPUT.PUT_LINE ('Student is registered for '||v_total||' course(s)'); */inner block*/EXCEPTION WHEN VALUE_ERROR OR INVALID_NUMBER THEN DBMS_OUTPUT.PUT_LINE('An error has occurred'); END; */outer block */ EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('There is no such student'); END;
  • 13. • The inner block has structure similar to the outer block. • It has a SELECT INTO statement and an exception section to handle errors. • When VALUE_ERROR or INVALID_NUMBER error occurs in the inner block, the exception is raised. • It is important that you realize that exceptions VALUE_ERROR and INVALID_NUMBER have been defined for the inner block only. • Therefore, they can be raised in the inner block only. • If one of these errors occurs in the outer block, this program will be unable to terminate successfully.
  • 14. User Defined Exceptions • Often in programs you may need to handle problems that are specific to the program you write. • For example, your program asks a user to enter a value for student_id. This value is then assigned to the variable v_student_id that is used later in the program. • Generally, you want a positive number for an id. By mistake, the user enters a negative number. • However, no error has occurred because student_id has been defined as a number, and the user has supplied a legitimate numeric value. • Therefore, you may want to implement your own exception to handle this situation.
  • 15. How to declare user-defined exception • A user-defined exception is declared in the declarative part of a PL/SQL block as shown below: DECLARE exception_name EXCEPTION; • Once an exception has been declared, the executable statements associated with this exception are specified in the exception-handling section of the block. • The format of the exception-handling section is the same as for built-in exceptions
  • 16. Raising Exception • user-defined exception must be raised explicitly. • In other words, you need to specify in your program under which circumstances an exception must be raised as shown : DECLARE exception_name EXCEPTION; BEGIN … IF CONDITION THEN RAISE exception_name; ELSE … END IF; EXCEPTION WHEN exception_name THEN ERROR-PROCESSING STATEMENTS; END;
  • 17. example declare e exception; vamt number(10); begin select amt into vamt from ac_det where acno=124; vamt:=vamt-77000; if(vamt<2000) then raise e; end if; exception when e then dbms_output.put_line('Minimum balance amount conflict'); * end; SQL> / Declare exception if the particular data is not found Raise exception ‘E’ If ‘E’ is exception the it will be displayed as ‘minimum amount conflict’