9-8. Associating Error Numbers with Exceptions That Have No Name

Problem

You want to associate an error number to those errors that do not have predefined names.

Solution

Make use of PRAGMA EXCEPTION_INIT to tell the compiler to associate an Oracle error number with an exception name. This will allow the use of an easy-to-identify name rather than an obscure error number when working with the exception. The example in this recipe shows how an error number can be associated with an exception name and how the exception can later be raised.

CREATE OR REPLACE FUNCTION calculate_salary_hours(salary  IN NUMBER,                                               hours   IN NUMBER DEFAULT 1) RETURN NUMBER AS BEGIN   RETURN salary/hours; END; DECLARE   DIVISOR_IS_ZERO  EXCEPTION; ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.