APEX-AT-WORK no image

Ignore sql error messages in pl/sql process

Von Tobias Arnhold 11.16.2009
Have you experienced the case that you want to execute a process and when a specified error occurs then it should go on like nothing happened.

In my case I had several pl/sql processes and one was to delete a database link. In my special case there shouldn't be an error if no database link exists.

Here is the code snippet for it:

declare
-- error variable
v_no_link EXCEPTION;
-- Map error number returned by raise_application_error to user-defined exception.
PRAGMA EXCEPTION_INIT(v_no_link, -2024);
-- About the error: http://download.oracle.com/docs/cd/B28359_01/server.111/b28278/e1500.htm#sthref1158

begin
-- Drop existing database link
EXECUTE IMMEDIATE 'drop database link ' || UPPER(:P1_I_INSTANCE_NAME);

EXCEPTION
WHEN v_no_link THEN
null;
--WHEN OTHERS THEN
-- raise_application_error(SQLCODE, 'SQLERRM');
end;

More information: PL/SQL User's Guide and Reference - Error Handling