In order to show the line number where the exception is thrown, you can do it by using
DBMS_OUTPUT.put_line ( 'Error raised: '|| DBMS_UTILITY.FORMAT_ERROR_BACKTRACE || ' - '||sqlerrm);
Example
declare
clientrow prod.client%rowtype;
begin
dbms_output.enable(null);
select *
into clientrow
from prod.client;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line ( 'Error raised: '|| DBMS_UTILITY.FORMAT_ERROR_BACKTRACE || ' - '||sqlerrm);
end;
Since Oracle Database 10g, Oracle has added DBMS_UTILITY.FORMAT_ERROR_BACKTRACE , which can and should be called in your exception handler. It displays the call stack at the point where an exception was raised, even if the function is called in a PL/SQL block in an outer scope from that where the exception was raised. Thus, you can call DBMS_UTILITY.FORMAT_ERROR_BACKTRACE within an exception section at the top level of your stack and still find out where the error was raised deep within the call stack.
The following error mesasge is shown when there are multiple rows in the table client.
Error raised: ORA-06512: at line 7
- ORA-01422: exact fetch returns more than requested number of rows
Oracle ORA-06512 is the catch-all Oracle error for PL/SQL exceptions.
Oracle ORA-06512 will generally appear as part of a message stack in which the message directly preceding Oracle ORA-06512 will list the reason for the error.
In above example, this user finds himself being thrown Oracle ORA-06512 and ORA-01422 while attempting to retrieving one row into clientrow varaible.