How to Handle Errors in PL/SQL

In this article I am going to explain how to handle errors in PL/SQL.
  • 2180

Introduction

PL/SQL is define as procedure language structure query language.  PL/SQL is developed by oracle. PL/SQL supports many feature like variables, loops, conditions  and exceptions. It also support the concept of array. In present time PL/SQL is integrated component of oracle software. SQL provide limited support for advance programming and PL/SQL fill this gap.

 Block is a basic unit of a PL/SQL application. This block is collection of PL/SQL statements grouped as logical unit. Using  PL/SQL blocks you can create five different type of program units.

  • Stored Function
  • Stored procedure
  • Anonymous Block
  • Trigger
  • Package

Exception Handling

An exception is the pre defined or user defined application error that arises during the execution of a program. Exceptions are nothing it is an abnormal condition. To handle these error or abnormal condition known as exception handling. In PL/SQL we can handle errors that raises by PL/SQL program.  

Example of While Loop Statement 

declare
st_rec student%rowtype;
begin
dbms_output.enable;
select * into st_rec FROM student where s_id=2;
exception
when TOO_MANY_ROWS THEN
dbms_output.put_line('TOO_MANY_ROWS raised');
when others then
null;
end;


© 2020 DotNetHeaven. All rights reserved.