How exceptions are raised in oracle?
Oracle exceptions are raised internally and user need not explicitly raise them. For example, when a number is attempted to be divided by ZERO, ZERO_DIVIDE exception is raised.
User defined exceptions need to be raised explicitly using RAISE command.
Example:DECLARE
total_stock NUMBER := 100;
cust_sales NUMBER;
sales_exceeded EXCEPTION;
BEGIN
SELECT SUM (sales) INTO cust_sales
FROM invoice WHERE customer_id = 1001;
IF cust_sales > total_stock
THEN
RAISE sales_exceeded;
END IF;
EXCEPTION
WHEN sales_exceeded
THEN
DBMS_OUTPUT.PUT_LINE
(' Customer sales exceeded the stock quantity’);
END;
How exceptions are raised in oracle?
There are four ways that you or the PL/SQL runtime engine can raise an exception:
1. Exceptions are raised automatically by the program.
2. The programmer raises a user defined exceptions.
3. The programmer raises pre defined exceptions explicitly.
How exceptions are raised in oracle?
Internal exceptions are raised implicitly by the run-time system. However, user-defined exceptions must be raised explicitly by RAISE statements.