what are the raising expections in pl sql?

What are Raising Exceptions in PLSQL?

  • More often than not so a special case is brought up in your application, Oracle Database will do the raising. That is, some sort of issue has happened during the execution of your code. You have no influence over that; when the special case has been raised, everything you can do is handle the exemption — or let it “escape” unhandled to the host condition.
  • You can be that as it may, raise exemptions yourself in your own code. For what reason would you need to do this? Since only one out of every odd mistake in an application is the consequence of a disappointment of inside handling in the Oracle database.
  • It is additionally obtained that a specific information condition establishes an error in your application, where case you have to stop the handling of your calculations and, very likely, tell the client that something isn’t right. become an expert in pl sql through **pl sql online training **

PL/SQL offers two different ways for you to raise an exemption:
The RAISE articulation
The RAISE_APPLICATION_ERROR worked in a technique
Obviously, you could likewise drive the raising of a special case by Oracle, with code this way:
Start
my_variable := 1/0;
END;
However, I am showing how to end square execution with parcels more control and data than that will show for you.
RAISE
Use RAISE to raise a formerly characterized exemption. It could be a framework special case, gave by PL/SQL itself, for example, NO_DATA_FOUND. Then again it could be an exemption that you show yourself.
Assume I have a technique that acknowledges another compensation to be rolled out to a worker. The standard you need to implement is that the new compensation cannot be negative. This is a kind of “significant worth error”, so you could raise that pre-characterized exemption.
Make OR REPLACE PROCEDURE use_salary (salary_in IN NUMBER)
AUTHID DEFINER

IS
Start
In the event that salary_in < 0
At that point
RAISE VALUE_ERROR;
END IF;
… rest of the method
END;
At the point when you run this technique as follows:
Start
use_salary (salary_in => - 1);
END;
You will see this mistake:
ORA-06502: PL/SQL: numeric or esteem mistake
So you prevented the program from proceeding, and that is great. It can, in any case, to individuals keeping up your code and clients seeing your error message to count on the nonexclusive PL/SQL special case.
So you could pronounce your own special case in the very same manner that PL/SQL characterizes exemptions like VALUE_ERROR.
Which most likely makes them figure: how does PL/SQL characterize these special cases? They are, generally, found in a unique bundle named STANDARD. You most likely haven’t known about it, and that is OK. It is one of the two default bundles of PL/SQL: STANDARD and DBMS_STANDARD.
As a matter of course, I apply that you can refer components in these programs without including their bundle name. For instance, I could reference VALUE_ERROR in the use_salary system as follows:
Methodology use_salary (salary_in IN NUMBER)
AUTHID DEFINER
IS
Start
On the off chance that salary_in < 0
At that point

RAISE STANDARD.VALUE_ERROR;
END IF;
In any case, I don’t need to. In the event that the compiler can’t generally resolve the reference to VALUE_ERROR (without the program name), it will at that point check whether that identifier can be settled in STANDARD or DBMS_STANDARD.
Also, on the off chance that we look inside the STANDARD bundle, we discover code this way:
VALUE_ERROR exemption;
program EXCEPTION_INIT(VALUE_ERROR, ‘- 6502’);
How about we apply that equivalent procedure in use_salary:
Make OR REPLACE PROCEDURE use_salary (salary_in IN NUMBER)
AUTHID DEFINER
IS
negative_salary EXCEPTION;
PROGRAM EXCEPTION_INIT (negative_salary, ‘- 6502’);
Start
On the off chance that salary_in < 0
At that point
RAISE negative_salary;
END IF;
… rest of the strategy
END;
What’s more, when I execute the methodology and pass it - 1, I see a similar error data.
ORA-06502: PL/SQL: numeric or esteem error
So what’s the upside of changing to possess exemption? For this situation (up until now), minor: Your code raises an exemption which by name lets you know and anybody keeping up the code later what the issue is.
The data displayed to the client, be that as it may, is not anymore useful than previously. On the off chance that you need to change that message to something actively reasonable to clients, you will need to “switch” to RAISE_APPLICATION_ERROR.
These are the best-known facts about What are Raising Exceptions in PLSQL, in upcoming articles, I will update more data on this topic through the sql online training

#plsql #sql #sqlcourse #sqlonlinetraining #plsqltraining

1.50 GEEK