drop procedure if exists in DB Oracle

Fawi picture Fawi · Feb 20, 2014 · Viewed 13.3k times · Source

Can someone tell me how I can drop a PROCEDURE in Oracle, but just if it exists ?

DROP PROCEDURE IF EXISTS XYZ;

The above does not work.

Answer

René Nyffenegger picture René Nyffenegger · Feb 20, 2014

If your goal is to eliminate error messages in a script, then you can try

begin
   execute immediate 'drop procedure xyz';
exception when others then
   if sqlcode != -4043 then
      raise;
   end if;
end;
/