Raising an Exception Local PL/SQL Block : Raise Exception « PL SQL Programming « Oracle PL/SQL Tutorial






SQL> --
SQL>
SQL>
SQL> create or replace function f_get_speed(i_distance NUMBER, i_timeSec NUMBER)
  2  return NUMBER
  3  is
  4    v_out NUMBER;
  5  begin
  6
  7    begin
  8      v_out:= i_distance/i_timeSec;
  9    exception
 10        when zero_divide then
 11        DBMS_OUTPUT.put_line('Divide by zero in the F_GET_SPEED');
 12    end;
 13    return v_out;
 14  end;
 15  /

Function created.

SQL>
SQL> select f_get_speed(1, 0) from dual;

F_GET_SPEED(1,0)
----------------


Divide by zero in the F_GET_SPEED
SQL>








24.16.Raise Exception
24.16.1.User-Defined Errors
24.16.2.Raise Exception in a function
24.16.3.Raising an Exception Local PL/SQL Block
24.16.4.Avoiding exceptions raised in declaration part and exception handler
24.16.5.Raising an Exception in the Declaration Section
24.16.6.Exceptions Raised in the Exception Handler
24.16.7.Raising NO_DATA_FOUND
24.16.8.Raising a custom exception
24.16.9.Using WHEN OTHERS clause
24.16.10.Using SQLCODE and SQLERRM
24.16.11.Propogating a Server-side Customized Error Number and Error Message to client program using PRAGMA EXCEPTION_INIT