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.
IF EXISTS in Oracle Oracle does not provide IF EXISTS clause in the DROP TABLE statement, but you can use a PL/ SQL block to implement this functionality and prevent from errors then the table does not exist. This approach works faster and requires less resources from the database.
The syntax to a drop a procedure in Oracle is: DROP PROCEDURE procedure_name; procedure_name. The name of the procedure that you wish to drop.
You cannot DROP tables in procedure using the DROP command. You need to use EXECUTE IMMEDIATE to run DDL commands in PL/SQL. Save this answer.
The DROP PROCEDURE statement drops a standalone procedure from the database.
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;
/
You can also check dictionary view before:
SELECT * FROM USER_PROCEDURES WHERE PROCEDURE_NAME = 'XYZ'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With