Search code examples
oracle-databaseprocedure

drop procedure if exists in DB Oracle


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.


Solution

  • 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;
    /