Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is user define exception and example



What is user define exception and example..

Answer / harinadh bolisetti

PL/SQL allows developers to define their own exceptions.
User can define the error/exception programmatically based on the business rule.

1. Define Exception
---------------------
We need to define the exception before we raise and handle. User Exceptions are defined using keyword EXCEPTION in declaration section of the block.
The syntax is as follows

<exception_name> EXCEPTION ;


2. Raise the Exception
--------------------------
Once the exceptions are defined , they need to be raised anywhere in the body depending upon predefined logic. User exceptions are raised using the keyword RAISE.
Syntax is as shown below

RAISE <exception_name>

3. Handle the Exception.
--------------------------
User exception are handled in the same way predefined exceptions are handled. They are handled in exception block using WHEN .. THEN keyword
Syntax is as shown below

WHEN <exception_name> THEN


example
----------------
DECLARE
low_sal EXCEPTION;
min_sal NUMBER:= 10000;
new_sal NUMBER:= 8000;
BEGIN
INSERT INTO EMP_EXC_DEMO(EMPNO, DEPTNO, SAL)
VALUES (4000,20,new_sal);
IF new_sal < min_sal THEN
RAISE low_sal;
END IF;
commit;
EXCEPTION
WHEN low_sal THEN
Rollback;
DBMS_OUTPUT.PUT_LINE ('Salary is less than '||min_sal);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE (SQLERRM);
END;

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

what is the use of HASH, LIST partitions?

1 Answers   ITC Infotech,


What is sql in java?

0 Answers  


How to install oracle sql developer?

0 Answers  


Can we debug stored procedure?

0 Answers  


What is optimistic concurrency control? : Transact sql

0 Answers  


How do you select unique values in sql?

0 Answers  


What are sql functions? Describe in brief different types of sql functions?

0 Answers  


What is meant by Join? What are the different types of Joins available? Explain.

5 Answers   Cap Gemini,


Can you have multiple SPs with the same name on a database?

6 Answers   CGI,


Which operator is used in query for pattern matching?

0 Answers  


How will you distinguish a global variable with a local variable in pl/sql?

0 Answers  


Suppose a student column has two columns, name and marks. How to get name and marks of the top three students.

0 Answers  


Categories