Oracle PL/SQL - Assigning a Name to Predefined Exception Code

Introduction

Oracle can assign a name to a predefined exception by using a PRAGMA command.

An exception handler that checks for the e_deadlock_detected exception is easier to understand.

procedure p_updateLoc(i_deptno_nr NUMBER, i_new_loc_tx VARCHAR2)
  is
    v_error_nr NUMBER;
    e_deadlock_detected exception;                                    
    pragma exception_init(e_deadlock_detected,-60);                   
begin
   update dept
   set loc=i_new_loc_tx
    where deptno=i_deptno_nr;
  exception
    when e_deadlock_detected then                                     
       v_error_nr:=sqlcode;
       insert into t_LogError (error_tx)
              values(i_deptno_nr||':'||v_error_nr);                   
       raise;                                                         
end;
/

Related Topic